![]() GraphQL is a query language, while REST is a design principle. The study shows a drastic reduction in the number of fields and size of returned JSON documents when using GraphQL instead of REST-based APIs. GraphQL is a better fit for complex systems that: The API provides them with the rest of data so you can discover actions and resources by inspecting the API’s responses. The advantage of HATEOAS is that you don’t need to know all URIs up front. HATEOAS is a principle of REST service that adds hypermedia links to REST responses to help discover all available resources. One of the key principles of REST is Hypermedia as the Engine of Application State (HATEOAS). GraphQL has more coupling between the client and the server because the client needs to understand the schema to make a query. That's what most JSON APIs are today.- Roy T. Imagine how poor the Web would have been if we had limited HTML to what was needed by an FTP client. Then the client needs to interpret the encoded string to figure out it's an image. You can send an image by encoding it as a base64 string and including it as a string in your GraphQL query. On the other hand, GraphQL is more complicated. With REST, you can just respond with the image/jpeg media type. Let's say you wanted to transfer an image file. GraphQL is limited to JSON as the media type, while REST can use all HTTP media types. GraphQL queries are more complex and can include multiple fields, making it difficult to cache the results of these queries. On the other hand, caching in GraphQL is more complex due to the nature of the queries and representations. This means that the resources requested can easily be cached and reused without requiring any additional processing. The implementation of caching in GraphQL requires more effort and complexity compared to REST.Ĭaching in REST is relatively simple as it uses a uniform resource representation. The study also shows that it is not straightforward to refactor API clients to use complex GraphQL queries due to the tendency of developers to organize their code around small functions that consume small amounts of data. GraphQL can reduce the size of the returned JSON documents by 94% in terms of the number of fields and 99% in terms of bytes, according to the study of 24 queries performed by seven open-source clients of two popular REST APIs (GitHub and arXiv) and 14 queries performed by seven empirical papers. They need to reduce bandwidth usage for the mobile app. That's exactly why Facebook engineers created GraphQL. ![]() REST has high bandwidth usage because of the chatty interface. This standardized form leads to over-fetching or under-fetching of data.ĭetailed comparison of GraphQL and REST: Bandwidth The trade-off, though, is that a uniform interface degrades efficiency, since information is transferred in a standardized form rather than one which is specific to an application’s needs. The main disadvantage of REST design is a standardized form of representing resources.Įven Roy Fielding recognized it in his dissertation:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |