REST or GraphQL

Youngmin Park
2 min readDec 28, 2020

I’ve been using REST so far. but I’ve heard good things about GraphQL. I’ve never used GraphQL yet but I want to.

So I wanted to learn difference between REST and GraphQL. and what is the benefit of using GraphQL over REST.

Before dive into the difference between these two.

Let’s check what is REST first.

REST:

What is REST?

REST is acronym for REpresentational State Transfer. It is architectural style for distributed hypermedia systems and was first presented by Roy Fielding in 2000 in his famous dissertation. (according to https://restfulapi.net/).

REST is a resource.

REST uses a resource identifier to identify the particular resource involved in an interaction between components.

and RESTful API looks like hypertext.

Benefits of REST?

One of the main benefits is that REST is scalable. and flexibility.

The key of REST is that everything is a resource that’s identified by a URL.

It allows developers to scale products and applications indefinitely without much difficulty.

Limitations of REST?

Over Fetching — Over-fetching is fetching too much data, meaning there is data in the response you don’t use.

Under Fetching — Under-fetching is not having enough data with a call to an endpoint, forcing you to call a second endpoint.

also one of the main limitations is the round trips. RESP API does not provide all the required data in one request. Therefore it is required to do multiple trips to access all data.

GraphQL:

what is GraphQL?

GraphQL is a query language.

This query language is mainly used in APIs and to fulfill queries with the existing data.

example of using GraphQL

You can request only something you want to fetch from data.

the request can be tailored to match the exact requirement. which mean it prevent Over-fetching and Under-fetching.

Benefits of GraphQL?

In addition to prevent Over and Under fetching and Tailored requests to the requirement that I mentioned above.

it allows developer can fetch data with a single API call.

Autogenerating API documentation.

API evolution without versioning.

Limitations of GraphQL?

Although GraphQL has some benefits over REST. There is still some limitations.

One of the main limitations is the performance issue when it comes to complex queries. Also it does not handle file uploading.

but when it comes to small application, performance is more fast.

Conclusion

GraphQL and REST are two approaches to API architecture.

Certainly, GraphQL has many advantages over REST but you should consider a size of project and complexity.

You will need to consider many factors, and need to understand the limitation beforehand.

--

--