I was talking to someone recently who said they are skipping the development of HATEOAS REST endpoints completely in favor of GraphQL. So I'm curious as to what the criteria set is for deciding when to use GraphQL vs. HATEOAS or is GraphQL just a better choice in general for an API Gateway / Edge Server architecture?
If you are aiming to develop an API to be used on a mobile application you should have GraphQL as first option because bandwidth usage matters. If your application requires a robust API, with caching and a monitoring system you should go with REST.
A lot of the cool stuff you can do in GraphQL can be done in REST, but GraphQL has no HATEOAS.
Regarding performance, gRPC is considerably faster than GraphQL, thanks to the Protobuf and HTTP/2. The payload data is serialized into binary format, which reduces its size and makes it more efficient than text-based formats JSON or XML.
GraphQL performance is fast and Rest are multiple network calls take up more time. GraphQL development speed is rapid and Rest are slower.
The pros and cons of each are:
Pro:
Con:
Pro:
Con:
One interesting comparison is that people use GraphQL as a frontend for REST APIs, but no-one in their right mind would consider doing the converse. If you go for a federated / microservices design, so one GraphQL server fronts for others, they can use a common specification of the API between the frontend and the microservices; this is less certainly true if the microservices are REST.
I think that so long as you have in mind the right questions to ask, GraphQL is going to be an important part of a well-designed system. Whether to skip HATEOAS entirely is unfortunately, "it depends".
My own experience, plus Phil Sturgeon's GraphQL vs REST: Overview
I love that Ed posted a link to my overview, but there's another article that I believe to be more relevant than that one.
The representation of state is completely different between the two.
https://blog.apisyouwonthate.com/representing-state-in-rest-and-graphql-9194b291d127
GraphQL is entirely unable to offer a series of "next steps" in a meaningful and standardized way, other than maybe shoving an array of strings containing potentially relevant mutations that you should try to hit up.
Even if you do that, it certainly cannot help you communicate with other HTTP APIs, which is a real shame.
Anyway, it's all that article! :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With