Reputation: 9769
I want to know what are all reasons of qraphQL to be used instead of rest api.
As much I know instead of making multiple requests (to reduce HTTP request), can make a group of HTTP requests in one request using graphQL.
Can anybody describe little more, please?
Thanks in advance.
Upvotes: 4
Views: 1617
Reputation: 1807
There are many articles covering this question in more details available on the internet. I am trying to give a short overview here.
GraphQL offers a couple of advantages over REST.
Main difference
In a REST interface, everything is about resources. For example, you'd get the resources "car" with ID 25 and ID 83 by calling an endpoint like this:
GET /cars/25
GET /cars/83
Note, how you have to call the interface twice. The endpoint ("cars") and your resource are coupled.
In GraphQL you could get both cars with one call, using this example query:
GET /api?query={ car(ids: [25, 83]) { model, manufacturer { address } } }
Note, how you even specified the exact data you want to fetch (model, manufacturer and its address). Compared to REST, the endpoint ("api") is not resource-specific anymore.
Some advantages
Upvotes: 8