GraphQL is a query language that lets your client request the server to send only the required data.
Let's deep dive into it. ๐งต๐๐ป
GraphQL was created by developers at Facebook in 2012.
GraphQL was developed to support the complicated data structures required to show the Facebook News Feed on the mobile application.
Using GraphQL, the client can request the necessary data using a single endpoint with a defined schema.
Considering you're building a blogging platform, you will need to fetch posts, author, published date, comments, and other associated data with a particular post.
With a standard REST API, you can design such an API very easily.
But now consider that you want to display comments only on the web app, not the mobile app.
It's almost impossible to achieve this with a single REST API.
This is where GraphQL can help you.
The client can ask for the data they need, and the server will return with only that data.
GraphQL relies on a strongly typed schema.
This means that the schema acts as a contract between the client and the server. The predefined schema is what allows the client to specify the exact shape of the data returned.
This Schema is known as Schema Definition Language.
Schema Definition Language is nothing but the syntax of writing schemas in GraphQL query language, and it's pretty intuitive.
Consider the `User` schema below written in Schema Definition Language: ๐๐ป
The `User` type has two fields, `name` and `email` with type String.
The exclamation mark (!) at the end depicts that the fields are required.
Moving forward, Schema Definition Language allows you to establish relationships between types.
For example, a `Blog` is associated with a particular `User`.
There are two GraphQL operations - Queries and Mutations using which you can fetch data and save data to the GraphQL server.
โพ Queries
When requesting data from a GraphQL server, the client has to send some information to the server. Based on this information, the server will send the response. This information is known as a query.
โพ Mutations
When you want to save data to a GraphQL server, you can use a "mutation". You can create, update, and delete data from a GraphQL server using mutations.
The ability of GraphQL to define the exact request and response structure helps us cut down on the resources and bandwidth required to fetch data.
Hence, GraphQL APIs would be a great choice to reduce the number of queries needed to fetch the necessary data.
With that being said, this is the end of this thread. We hope you found this thread helpful.๐
There are different kinds of specifications available that you can use while building an API.
In this thread, we will talk about the OpenAPI spec.
๐งต ๐๐ป
In simple terms, OpenAPI spec is a format to define structure and syntax for REST APIs.
OpenAPI spec provides a standard that allows both humans and computers to discover and understand the service's capabilities without access to source code, documentation, or traffic inspection
- Public API
- Private API
- Partner API
- Composite API
Let's discuss them in detail ๐งต๐๐ป
1๏ธโฃ Public API
Public APIs are accessible to all developers with a low or moderate level of authentication and authorization.
For example, the Windows API of Microsoft is a public API.
Stability is an essential factor of any public API. Any changes in the public API, let's say adding a new parameter, might break the applications that depend on that API.