Anatomy of REST API request

Anatomy of a REST API request refers to the different parts or elements that make up an HTTP request sent to a RESTful API.

The main elements of an API request include:

  • HTTP Method: The type of request being made, such as GET, POST, PUT, PATCH or DELETE. This method defines the type of action that the client wants to perform on the resource.
  • URI: The endpoint or location of the resource being requested. This is usually in the form of a URL or URN.
  • Headers: Additional information about the request, such as authentication details, content type, or accept type.
  • Query Parameters: Additional information that can be passed in the request to filter or sort the data returned in the response.
  • Request Body: Additional information or data being sent to the server. This is typically included in POST, PUT, PATCH and DELETE requests.

An Example of a REST API request:

POST /users
Content-Type: application/json
"firstName": "techalmirah",
"lastName": "com",
"email": "",
"password": "password1234"

The above example is a REST API request to create a new user.

The HTTP Method is POST, the URI is /users, the headers include the Content-Type, and the request body contains the data for the new user.

It’s worth noting that not all requests will include all the elements mentioned above, for example GET requests typically don’t include a request body.