Tech Corner
How technical are APIs?
The topic of APIs may seem daunting, but it's simply communication between two systems. Here's a quick walkthrough of what APIs are, starting with the REST API.
GraphQL is a query language and server-side runtime for application programming interfaces (APIs) that prioritizes giving clients exactly the data they request and no more. GraphQL is designed to make APIs fast, flexible, and developer-friendly.
It can even be deployed within an integrated development environment (IDE) known as GraphiQL. As an alternative to REST, GraphQL lets developers construct requests that pull data from multiple data sources in a single API call.
Additionally, GraphQL gives API maintainers the flexibility to add or deprecate fields without impacting existing queries. Developers can build APIs with whatever methods they prefer, and the GraphQL specification will ensure they function in predictable ways to clients.
GraphQL was developed internally by Facebook, which started making use of it for mobile applications in 2012, before the specification was publicly released in 2015. On 7 November 2018, the GraphQL project was moved from Facebook to the newly-established GraphQL Foundation, hosted by the non-profit Linux Foundation.
%20(1)%20(1).jpg)
There are several open-source projects that make use of GraphQL. Some of these projects include:
Basically, GraphQL is used to speed APIs up, increase their flexibility, and make them more developer-friendly.
API developers make use of GraphQL for the purpose of creating a schema that describes all the possible data that clients can query through that service.
GraphQL follows the same set of constraints as REST APIs, but it organizes data into a graph using one interface. Objects are represented by nodes (defined using the GraphQL schema), and the relationship between nodes is represented by edges in the graph. Each object is then backed by a resolver that accesses the server’s data.
When a GraphQL server responds to an end user’s request, it begins with the query root, and the resolver executes every field on the requested object. A key-value map houses each field’s values, and some return another object selecting another set of fields. This continues until only a string or a number is returned. The server then responds with a nested set of objects, as requested by the end-user
REST, on the other hand, is an architectural concept for network-based software while GraphQL is a query language, a specification, and a set of tools that operates over a single endpoint using HTTP.
In addition, over the last few years, REST has been used to make new APIs, while the focus of GraphQL has been to optimize for performance and flexibility.
When using a REST API to fetch information, you’ll always get back a complete dataset. For example, if you wanted to request information from two objects, you’d need to perform two REST API requests. The advantage of REST APIs is its simplicity—you have one endpoint that does one task, so it’s easy to understand and manipulate. In other words, if you have X endpoint, it provides X data.
Conversely, if you wanted to gather some information from a specific endpoint, you couldn’t limit the fields that the REST API returns; you’ll always get a complete data set. This phenomenon is referred to as over-fetching. GraphQL uses its query language to tailor the request to exactly what you need, from multiple objects down to specific fields within each entity. GraphQL would take X endpoint, and it can do a lot with that information, but you have to tell it what you want first.
In essence, GraphQL is extremely powerful, once you know how to use it. Because you are only fetching the data that you require, you limit the amount of processing required. As you begin to look at automation, these savings really start to add up.
The advantages of GraphQL are:
The disadvantages of GraphQL are: