REST vs gRPC vs GraphQL
February 1, 2023
💡 How to choose the right API framework for your needs.
Building a new application and confused about all of the API framework options? You aren't alone. There are a lot of options for you and your team to build your back-end and front-end APIs, so we will go through the options and compare them. Don't worry we won't bring up SOAP/XML or any other older API technology.
TLDR: Take a look at our comparison table at the end of this article.
REST APIs use HTTP actions as "verbs". HTTP GET is used to retrieve information while HTTP POST is usually used to create an object.
You will see that we've used the word "usually" a few times and that is because REST isn't really a framework and its rules are very loose. While most REST-based APIs are similar, they can also be very different and are almost always a dis-organized can-of-noodle-soup in terms of objects, path structures, and HTTP verbs.
JSON is almost always used as the data format. OpenAPI (previously known as Swagger) can be used to define the API.
REST can cause a lot of HTTP calls to pick up all of the data that you need for a front-end application. You call
/user to get the current user, then call
/todos to pick up their TODOs, then
/news to pick up your app's news, ...
GraphQL comes to the rescue by creating a powerful querying language which can also specify which fields and objects to return.
While GraphQL has nowhere near the popularity of REST for BE <> FE APIs, some large companies have moved to this framework, most notably Shopify.
The newest entrant into API frameworks is Google's gRPC. (no brownie points for guessing what the ‘g' stands for)
The main premise for gRPC is that the actual mechanics of the call are hidden and the API is defined as a series of function/methods calls like any other in your code.
The actual communication is somewhat hidden as well, but is usually run through HTTP/RPC and almost always uses the Protobuf data format.
Protobuf is sent in a binary format and so it is very compact and fast. This is one of the main reasons that gRPC+Protobuf are popular with internal micro-services. There currently isn't a lot of use of gRPC between FE and BE due to the lack of support on front-end frameworks.
|Used for FE < - > BE
|✅ Almost always
|❌ Not really (yet)
|Used for micro-services
|🤷♂️ Sure, but...
|🤷♂️ Sure, but...
|✅ Oh yea!
|Used for customer-facing API
|✅ REST is well understood and has the most language support
|🤷♂️ Unless your customers have very technical developers, GraphQL could slow them down in implementing your API
|❌ While this should be the best choice, there simply isn't sufficient language support nor wide-spread understanding of gRPC to make it your first choice for a public API.
|🤷♂️ JSON (text)
|🤷♂️ JSON (text)
|✅ Protobuf (binary)
|❌ OpenAPI / Swagger (sometimes)
|✅ GraphQL Schema
|✅ Protobuf schema
|❌ Lots of independent calls plus text JSON results make REST the slowest option
|🤷♂️ GraphQL can be quick if you return just the needed fields and also return other relevant objects (plus use GZIP with the HTTP response). But if you run it like REST with single object queries, then it will be just as slow.
|✅ gRPC is by far the fastest option as the data is in binary and the results can be anything you want (and not just a single type of object as in REST)
The good news is that Unified.to's APIs are accessible by all three API framework.