API is a common concept among software systems. Different software systems require to communicate with eachother to invoke some functionality or to exchange data. Since it’s a frequent requirement, it’s important to have a set of standards. There are different patterns and best practices that can be used to design and implement APIs.
RESTful API
- REST APIs are designed around resources, which are any kind of object, data, or service that can be accessed by the client.
- They are mainly used for CRUD operations (Create, Read, Update, Delete) on resources.
- They use standard HTTP methods (GET: Read, POST: Create, PUT: Update, DELETE: Delete) and status codes to perform these operations on the resources.
- REST APIs are stateless, meaning that calls can be made independently of one another, and each call contains all of the data necessary to complete itself successfully.
GraphQL
- GQL is a query language for APIs and a runtime for executing those queries by using a type system you define for your data.
- Graphql APIs are designed with a schema that defines the types and fields that can be queried.
- The Client can request only the data it needs, and the server will return only the requested data.
- The shape of response follows the shape of the request.
gRPC
- It is designed for low latency and high throughput communication between microservices.
- gRPC is particularly suitable for microservices and between systems written in multiple programming languages due to its support for multiple programming languages.
- It based on HTTP/2, which is a binary protocol that is more efficient than HTTP/1.1.
- It uses Protocol Buffers as the Interface Definition Language (IDL) for describing both the service interface and the structure of the payload messages.
Webhooks
- Webhooks are user-defined HTTP callbacks, which are triggered by specific events.
- When an event occurs, the source site makes an HTTP request to the URL configured for the webhook.
- They are useful for integrating different systems or for events in asynchronous communication.
WebSocket
- WebSocket provides two-way (full duplex) communication channels over a single TCP connection.
- It enables interaction between a client and server in a real-time manner.
- It is particularly useful for applications that require real-time updates, such as chat applications, online gaming, and financial trading platforms.
Each of these standards are useful and are best practices for their specific use cases. It’s important to choose the right pattern based on the requirements of the system.