GraphQL vs. REST vs. RPC
REST is a concept to decouple server and client by providing an API providing access to server-side data as ressources and provide methods to change these ressources.
RPC on the other hand is a binary protocol for invoking Procedure at a remote-Computer. In its simplest form an port is opened processing data in an closed binary protocol. A more standard-approach would be using SOAP+XML.
GraphQL is a Query-Language, specification and set of tools operating on a single http-endpoint. With the query-language the client is allowed to define, which data it wishes to receive and thus possibly reducing the number of requests and the amount of data to be send.
With Spring-Boot and several other frameworks REST-endpoints are very easy to implement and allowing a good access to a domain-model. Some kind of operations don't act on a single ressource. They don't result in creating a new ressource or they maybe changing multiple ressources at once. Such operations are easier to implement as RPC-endpoint. That not neccessarily mean to switch to a different framework. It just means to distinguish between them, for example on URI-Level. With "/document/{id}" it's pretty clear, what ressource is affected. And with "/api/calculateCitationIndex" it's pretty clear, a remote-procedure is triggered (this one explains it well: https://www.smashingmagazine.com/2016/09/understanding-rest-and-rpc-for-http-apis/).
REST has the advantage to be cacheable, while GraphQL works better with evolving APIs and allowing to serve mutliple different clients (https://phil.tech/api/2017/01/24/graphql-vs-rest-overview/) - in fact some of the domain-knowledge is offloaded to the client (they need to know how the domain looks like to build their queries).
All variants can coexist in the same project and it maybe makes sense to utilize them. Within Payfree, the relevant Stores (depending on users coordinates), Configuration and Purchased items change a lot and are maybe better suited for GraphQL than REST.
In my opinion we need to ask:
- Will the API be public and do we allow to develop third-party-apps using that API (imagine it like twitter)?
- If yes: we should carefully design the api (considering also support for HATEOAS, Siren, or Hydra - containing more meta/schema-information)
- If no: REST is easy and fast to implement and we should be fine.
Also theres a flow-chart for easier decision on that topic: https://phil.tech/2018/05/21/picking-an-api-paradigm-implementation/