Why we needed it in the first place

Once upon a time an academic paper was made telling us how APIs ‘should be’ designed, and because we are suckers for consistency it since became the formal way of creating them.

We should have felt well rested by then, but turns out REST is not very RESTful.

The problem with REST

If you have worked with Rest rules before you know that each resource should have its own endpoint.

E.g if we have puppies and toys we would have to get the puppies on: /api/puppies

And if we want toys we would have to hit them on: /api/toys

Now imagine the scenario where we would want to get the toys of a puppy similarly we’ll fetch the endpoint: /api/puppies/1

But we wanted toys, why are we receiving the puppy’s gender and other pieces of information we don’t care about?

Another scenario is when we want to get two objects ,we have to send two requests to the server .

You could already notice that there is a bit of redundancy in the Rest pattern.

How does GraphQL replace REST

On bigger scales especially at facebook they noticed that this way of doing things isn’t very fruitful , so they had to make a move to overcome all the pitfalls of RESTful style APIs.

#graphql #javascript #web-development #rest #api

A Beginner’s Introduction to GraphQL
1.95 GEEK