Original Blog Post — https://codevampires.com/2018/09/07/is-graphql-flexible-than-restful-api/

I am writing this article because a few months ago I worked on a scraping application where I needed to scrape overwhelmed data per request using RESTful API. In this application my involvement was mainly in backend side, so on that time I took a lot of unspoken burden based on consumer demand, I need to write the same APIs multiple times for different data sets.

So, in this article I will try to focus on some situations and try to get out some points regarding, why GraphQL API is more flexible than REST API.

Let’s start,

What is GraphQL API?

GraphQL is a data query language developed internally by Facebook in 2012 before being publicly released in 2015.

Mainly GraphQL gives a complete and understandable description of the data in your API. By using GraphQL API, we can think completely new way about our API architecture, that is I think efficient and more flexible.

Send a GraphQL query to your API and get the response exactly what you need, nothing more and nothing less.

What is REST API?

One of the most popular type of API name is REST. It is a very traditional approach and commonly known as RESTful API.

REST allows easy and rapid evolution of an API design. REST demands the use of hypertext, which scales very well since the client and server are very loosely coupled.

RESTful APIs have four very important data transactions that uses HTTP requests to GET(READ), PUT(Edit), POST(Create) and DELETE data.

REST VS GraphQL API

Suppose, we need to scrape a news portal website where everyday thousands of news are published publicly and every news contains lots of information and overwhelmed user comments. If we use REST API for this system we have to make almost ten different API calls to get different information and each API call gives us in return a lots of information. Most of the time we just need one data suppose just ‘title’ of the news but our API response request contains hundreds of data records that’s very useless and we really don’t need. So REST gives us lots of excess which is very unnecessary.

But in GraphQL API If we want to developed same system we just need to make one API call and return It will gives us one response. GraphQL API is very specific and return It gives us what we exactly need.

So mainly GraphQL solve the over fetching and under fetching problem of REST API. That means, GraphQL things make more easier which retrieve and manipulate data more efficiency based on client request where, REST has no way to limit the response of data and always It’s contains subset of fields.