GraphQL vs REST
.
A Thread🧵
.
What is GraphQL?
GraphQL is basically a query and manipulation language for APIs, which describes a unique way to ask for data. Let's see how is it different from a REST API.

#100DaysOfCode #graphql #CodeNewbies

(1/8)
Basic Difference

A REST API is an architectural concept whereas GraphQL is a query language, a set of tools that operates over a *single endpoint* using HTTP. The focus of GraphQL in the past few years has been to optimize for performance and flexibility.
(2/8)
Suppose you wanted to gather some data from an endpoint, you can't limit the fields that the REST API will return as a response; ie you’ll always get the entire dataset. This is called over-fetching.

(3/8)
GraphQL, on the other hand, uses its query language to tailor the request to exactly what fields you need, ie you can ask for a particular set of fields and it'll return only those fields and not the entire dataset.
#DEVCommunityIN
(4/8)
And since you're only fetching the data you require, the amount of processing is reduced drastically, which makes GraphQL very, very powerful.

#CodeNewbie
(5/8)
Consider another case of REST APIs when you want to get both, the name of the user and their address, given the user_id. In that case, you'd have to make two api calls, one to let's say /api/users?user_id=1 and the other to /api/address?user_id=1. (Note that this is just an eg.)
In such cases where we need more data, we're bound to make multiple api calls. GraphQL on the other hand let's us obtain this data much more easily and efficiently, with a single api call to let's say /graphql, where you simply mention the query string and get back reqd. data!
Thus, there's no harm in concluding that GraphQL is pretty efficient and powerful as compared to REST APIs. Many organizations are slowly switching to GraphQL which asserts its power and popularity :)

#webdevelopment #code

(8/8)
You can follow @runtimeError20.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled:

By continuing to use the site, you are consenting to the use of cookies as explained in our Cookie Policy to improve your experience.