Benefits of REST: When to use REST instead of GraphQL?
REST has several benefits as an API standard, but these specific instances highlight when it’s better to use REST instead of GraphQL.
Smaller applications
GraphQL is perfect for larger applications (such as the Facebook NewsFeed that sparked its creation), but REST APIs can achieve the same effect with smaller applications. There’s less to worry about when it comes to fetching data, and sometimes the results can be achieved much quicker.
Analyzing errors faster
It’s also faster to understand errors in REST. If a request is not executed successfully, if there was an error or if a resource isn’t found, everything can be checked by looking at the response status code.
(REST request with error)
GraphQL, on the other hand, requires you to parse through messages to determine errors.
(GraphQL request with error)
Simpler queries
With REST, queries are straight forward. An endpoint will be responsible for a specific data type, it can be filtered using parameters. So the data endpoint response should not be a surprise.
Whereas with GraphQL, a query must be prepared which will include what data types & filtering you need. This could be a hindrance to developers as they would need to learn how to query the API.
Also due to the complex nature of GraphQL, it can make caching more difficult compared to REST.
Handling complex queries
With REST, it’s easier to handle complex queries. GraphQL only returns specific data points so it can be more challenging for developers to create custom queries from large data sets.
Also, the caching capabilities of REST are far less complicated than those of GraphQL. The responses of RESTful webservices fetching data can usually be cached easier (due to fewer parameters) than GraphQL queries.