Graphql vs rest

Published May 19, 2024

The content here is under the Attribution 4.0 International (CC BY 4.0) license

Introduction

This is a quick search done through Google Scholar using the keyword “REST versus Graphql”. The aim is to search for empirical data on the strengths and weaknesses of both approaches, as practitioners often argue that one is “better” than the other.

Often practitioners ignore that “best” might vary based on the context and level of knowledge of a given technology - this approach happens with the choice of using REST over GraphQL.

Approach to get information

  • Search is set to use any time
  • To sort by relevance and
  • to be of any time

Top 5 papers in the result:

  • REST vs GraphQL: A Controlled Experiment - https://arxiv.org/abs/2003.04761
  • REST or GraphQL? A Performance Comparative Study - https://sci-hub.hkvisa.net/10.1145/3357141.3357149
    • Additional material: https://speakerdeck.com/gustavopinto/rest-or-graphql-a-performance-comparative-study
  • Experiences on Migrating RESTful Web Services to GraphQL - https://link.springer.com/chapter/10.1007/978-3-319-91764-1_23
  • Performance Analysis of GraphQL and RESTful in SIM LP2M of the Hasanuddin University - https://ieeexplore.ieee.org/abstract/document/8878524
  • Migrating to GraphQL: A Practical Assessment - https://ieeexplore.ieee.org/abstract/document/8667986

Discussion

in this section, we will discuss the different features of each approach.

Data fetching

Data fetching is the most common theme when the subject is rest and GraphQL. both offer different ways of consuming information. Rest is based on the HTTP verbs to fetch data. Richardson’s Maturity Model explores the HTTP verbs more powerfully. The server is the one that offers different possibilities for fetching the data such as filters and transformers. However, it is less common to see restful API offering granularity over the data being returned. In other words, if the client doesn’t want the entire payload from my specific get request, the server will return it anyway this is the argument that gives the graph well its foundation. graph QL does offer granularity over the data being sent back from the server to the client. however, rest API can also implement this kind of behavior but before the graph QL this was not common.

Graph QL on the other hand does not care about each different age TTP verbs that the protocol offers it uses only post and the graph QL specification handles the different types of behaviors based on its language. To fetch data with graph QL queries are used. Those queries enable the client to specify what data it needs to be retrieved its properties filtering and transforming as well. Q graph QL needs specific tooling to handle the complexity of dealing with its standard and language to communicate with clients and servers. The following are the most used ones:

Given that each type was created at different times both are used today however graph QL got its popularity with the appealing data that is sent from the server to the client as its main feature. Studies have shown that in a controlled experiment, GraphQL takes less time to implement in comparison with Rest [1]

Rest API on the other hand head also exploded in standardization. The open API for instance is the most used project with restful API.

Examples of Rest APIs:

Error handling

Tools to consume graphql

inmsonia

postman

intellij text http

Resources

Blogs that might complement content

Youtube videos/Talks

References

  1. [1]G. Brito and M. T. Valente, “REST vs GraphQL: A controlled experiment,” in 2020 IEEE international conference on software architecture (ICSA), 2020, pp. 81–91.