Photo by Nate Grant on Unsplash

Why GrpahQL is a better alternative to REST?

Karthik Saravanan
2 min readFeb 27, 2022

--

Before we get into why GraphQL is a better alternative, let us understand what it is.

What is GraphQL?

GraphQL is a new API standard open-sourced by Facebook. It enables declarative data feeding. This means the client can specify what exactly it needs from API. GraphQL server exposes “Single endpoint” instead of multiple endpoints increasing the efficiency.

Why a better alternative to REST?

1. Efficient compared to REST.

GraphQL minimizes data transferred over the network. This increases the application performance in scenarios like low network coverage areas.

2. Rapid product delivery.

REST uses structured endpoints as per the data need of the client. The drawback here is that any minor change in the client requires changes in the endpoints to match the client changes.

Rapidly changing requirements on the client don’t go well with the static nature of the REST.

With graphQL, changes in the client don’t require changes on the endpoints improving the product feedback cycle and frequent product iteration.

3. Avoid over-fetching of data.

GraphQL allows the client to request only the required data. Therefore we avoid unnecessary downloading of data.

We can think of a scenario where we need only an id from the endpoint. But there can be additional data with the endpoint increasing the data transfer.

4. Avoid under-fetching of data.

For the under-fetching of data, we can think of a scenario where we don’t get enough data from the endpoint. We need to send multiple requests to the required data (n+1 request problem).

5. Better insightful analytics.

GraphQL uses the concept of the “resolver” function to collect the data requested by the client. Instrumenting and measuring the performances of these resolver functions provide insightful bottlenecks in our system.

It enables evolving API and deprecating unnecessary API features.

6. Schema and type system.

GraphQL uses a strong type system to define the capabilities of the API. All the types exposed in an API are written down in a schema using graphQL schema definition language.

Schema serves as the contract between the client and the server to define how a client can access the data.

Wrapping up...

GraphQL was developed to cope with the need for more flexibility and efficiency in client-server communication. It helps in rapid product iteration and faster development with its declarative nature offering many features over REST.

GraphQL doesn’t completely replace the REST. It is a better alternative to the REST. If you are developing a mobile application, GraphQL should be at the top of your list.

Happy reading 😀

--

--