There are five different parts to be found in the Http request:
- Method: The method describes the action to be performed. The methods could be POST, PUT, DELETE, GET.
- URL: It specifies the name on which the action is to be performed.
- Query parameters
- Headers: Headers are used to store the information about the request.
- Body: Body contains the additional data.
URL is broken down into several pieces:
For example: the request URL is: https://api.example.com/v2/user
- Scheme: https
- Host: api.example.com
- Base path: /v2
- Path: user
Note: The host and the base path would remain the same of an API, but the path differs depending upon the request.
Request Body
We mainly specify the request body in JSON format for some methods such as PUT, POST, etc. The body is treated as parameters like path in url.
Unlike these parameters, we create the schema for the request body that specifies how the JSON body would look like.
In REST, the response body could be anything, but mainly the response body is written in JSON format.
The response body is included in the response object. The response body has a schema to represent the structured data.
We can also have a separate response object for each HTTP status code returned.