In the world of software, one of the most important aspects is access to data. We need to read them, manipulate them according to our permissions, but we have to access the data. How do we do this? There are several ways to do this, but the most used is through an API.
An API is a communication between applications. It is a communication layer through which an application can read the data of another application. An example of this would be that Frontend can read data from Backend, but they could also read data from Facebook and make this data appear in another application, from Google, Twitter, etc.
The most used type of API is Rest but this is starting to change. Due to its high worldwide traffic, Facebook began to lack the use of Rest, which has led them to create new technologies to be able to bear the entire load. Because of this, they invented GraphQL.
GraphQL is a new kind of API that completely changes the Rest paradigm.
The birth of GraphQL caused a collective fear among developers: the death of REST was coming. This apparently is not true at all. According to what was reported by the specialized channel EDTeam, Rest continues to be used by giant applications run by this "GraphQL was created by Facebook for a very specific problem of theirs".
As mentioned previously, GraphQL comes to redefine the APIs. In details, it can be separated into two parts: the QL, which stands for Query Language or Query Language and this is nothing more than a syntax to query data with specific parameters. This type of language is always present on the Backend side, what GraphQL achieves is that these queries can be made on the client side.
But who processes those queries? The server processes these queries, connects to the database, and sends the desired information.
GraphQL has as one of its characteristics being completely independent of the language and the database, it does not have much relevance if it is a rational or non-rational database, it can even be a REST API, that is, it can be written with GraphQL above the GraphQL APIs.
For users of these query languages, both have similarities and characteristics that make them favorites of some, but there are differences between them that have tipped the balance in favor of one or the other among developers, with GraphQL having a slight favoritism during the years. last months.
One of the most notable differences between the two is that, in REST the backend controls the request, while in GraphQL the client is the one who controls the request, but what does this mean in particular?
To have a better understanding of this process, you must know what an Endpoint is: this is a URL created by the backend to which the developer connects to get all the user information he needs. Frontend connects to the Endpoint and downloads the data, but the information present there is defined by Backend.
In GraphQL, the client has a query language, it can then connect to the Endpoint and define what it is going to ask for. This is the main difference between GraphQL and REST: who controls the request.
Among other differences, one that stands out equally is that, in GraphQL the developer can connect to a single Endpoint and find there all the information and it can be filtered according to the need, while in REST, the developer must connect to different Endpoints: one dedicated to users, another to products, another to prices and according to what you get, build the information you need.
This and other differences make GraphQL prevail in use and favoritism over REST. The operation of this is simple and in three steps: describe your data in Backend, the client makes the request for the query language and after this, he gets exactly what he needs.
At Rootstack, several of our developers already work with GraphQL and you can join that team, just contact us on our social networks or through our emails to give you more information.
We recommend you on video