A REST API allows a user to interact with the server by creating requests and receiving responses. REST stands for Representational State Transfer and API stands for Application Programming Interface. A REST API is a type of API that follows a REST architecture.
There are six architectural constraints that all REST APIs follow:
Client-Server Architecture- this indicates that the client and the server are separate from each other and must be able to function independently.
Uniform Interface- the structure of the call and response must be uniform across all REST APIs.
Stateless- This means the server will not store a history of previous calls made to the server. Each call will be considered new.
Cacheable- all responses must be cacheable.
Layered System- It is possible to have many servers. The client should not be able to tell if it is connected to the end server or an intermediary server.
Code on demand (optional)- the server may return executable code to the client.
What Component are in a Request ?
HTTP Methods :
HTTP Methods represent an action to the server that u would like to complete.
POST: Create user information on the server.
GET: Get user information on the server.
PUT: Update and Replace the user information on the server.
DELETE: Delete the user information on the server.
REQUEST URL:
It indicate to the server what you are trying to do.
URL is separated in parts:
1. Base Path : refers to the common path of the API.
2. Endpoint : refers to the endpath of the end point.
3. Query : Query parameters are specified after the question mark in the endpoint in the Request URL.
Let's show the example:
{https://www.restapitesting.com/serach?limit=3&format=json}
Base Path : https://www.restapitesting.com
End Point : /serach
Query : ?limit=3&format=json
Request Header:
Every REST request must contain three HTTP header fields: Accept, Content-Type, and Cookie.
1. Accept Header:
The Accept header describes which format you want a response. For example, responses can be delivered either as XML or JSON . 2. Content-Type:
The content-Type describes the format the body of your request . For example, the body of your requests can be sent as JSON or XML, but you need to declare in the Content-Type header which one is being used.
3. Cookie:
The Cookie contains the authenticated session ID that you obtained after creating a REST API session.