DEV Community

loading...

Discussion on: 4 reasons why you should use GraphQL over REST APIs

kfwerf profile image
Kenneth van der Werf

Not really sorry, the first can be done as well with REST, if you would include all that info in the request for the post right? or is that not very RESTy? The last bullet i also still don't completely understand. A backend using rest could still easily consolidate those services?

Thread Thread
blessingartcreator profile image
Blessing Hirwa Author

GraphQL allows multiple resource requests in a single query call, which saves time and bandwidth by reducing the number of network round trips to the server. It also helps to prevent waterfall network requests, where you need to resolve dependent resources on previous requests. For example, consider a blog’s homepage where you need to display multiple widgets, such as recent posts, the most popular posts, categories, and featured posts. With REST architecture, displaying these would take at least five requests, while a similar scenario using GraphQL requires just a single GraphQL request.

If you put all of the requests in one API then you'll to write many lines of code compared to GraphQL and it'll increase execution time. The goal here is to make things simple and fast.

Thread Thread
andrewbridge profile image
Andrew Bridge

I understand that this is always touted as a big plus of GraphQL, but it's absolutely possible to do this with a REST API, check out the spec for JSON:API, which allows nested entity relationships to be defined as part of a single request.

That aside, if you have control over the API you're querying, there's no reason you can't define an endpoint that includes all the data you need in a single request anyway, right?

Thread Thread
blessingartcreator profile image
Blessing Hirwa Author

REST can do it but Graphql uses low bandwidth compared to REST, that was my point.

Some comments have been hidden by the post's author - find out more