REST API
REST API
REST: Representational state transfer application programming interface
It is a way for Applications to communicate over the web by following architectural principles. It is simple, scalable, and compatible with HTTP and HTTPS web standards.
Core Principles:
Stateless: Each request from the client to the server is complete. It contains all the necessary information to process the request. The server does not to store the client-specific session information to process it.
Client-Server Architecture: The client, the requester, and the Server the provider are two separate entities.
Uniform Interface: REST API must have a consistent and well-defined interface usually it should align with HTTP Standards.
Resources or EndPoint: represented by URLs. Example /user, /stock
HTTP Methods: Action on resources such as GET, POST, PUT, DELETE and PATCH
Representation: Representation of data usually XML or JSON.
Cacheablity: The response must explicitly mention whether it can be cached to improve performance.
Layered System: It can have layers like load balancer proxies or security layers on top of client-server interaction without affecting the functionality.
Code on demand: The server can send code to execute to the client. It is optional.
Components:
HTTP Methods (CURD):
GET: Retrieve Data from the server.
POST: Create a new resource.
PUT: Update or replace the existing resources.
PATCH: Partially update the resources.
DELETE: Delete the resources.
Endpoints and Resources: An Endpoint is a URL that points to specific resources or actions. Examples /users, /users/1
Get Shankar Duraisamy’s stories in your inbox
Join Medium for free to get updates from this writer.
Headers:
Headers are the key-value pair included in the HTTP requests and responses that provide metadata about the transactions
They help define the request/response format, authentication details, caching preferences, and more.
Types of Headers:
Request headers: It is sent by the client to provide additional information about the request
Example:
Authorization: Includes credentials for authentication.
content-type: Specify the format of the data being sent.
Accept: Specify the format of the data that the client can handle
Response headers: It is sent by the server. it is metadata about the response
Example:
Content-Type: Format of data returned i.e application/json, application/XML, etc.
Cache-Control: Provide caching instructions for the response.
Set Cookies: Sends cookies to the client.
General headers:
It applies to both the request and response but it does not fall under meta-data.
Example:
Connection: It indicates the connection open(keep-alive) or closed.
Entity headers:
It provides metadata about the body of the request or response.
Example:
Content-Length: the size of the body in bytes
Content-Encoding: Encoding method





