Payload in APIs

SECTIONS

Introduction

In the above sections we have been talking about sharing and exchanging of data between various apps and systems. In APIs, the data which a request contains is called payload. Each time, while the payload varies as per the request, the delivery has standardizations.
In other words, payload refers to the body in HTTP request as well as the response. This is completely optional and is dependent on the name of the HTTP method. Usually, curly brackets ‘{}’ are used to present payload in a request generally the request is sent across as a JSON file, which because of its lightweight, is a preferred choice for exchange of data.
Payloads play a crucial role in message protocol as this helps to segregate assisting data from actual data in a query string.
Let us look at an example-
If we consider this example, ‘Hello everyone!’ is the payload and all the other information is called overhead data as it represents the source and the destination.

Let’s look at a few payload formats. Usually, there are 3 formats for payload namely-

  • Request payload format
  • OK response payload format
  • Failed response payload format.
Each of these formats have a few parameters and sub-elements which have been explained below.

  • Request payload format- This request message always begins with the name of HTTP method like GET, POST, PUT, DELETE, etc. The ownership of the preparation and sending HTTP request message along with the correct name of the HTTP method basis the operation is on the consumer.
For example, GET method is used to execute READ operation and the HTTP request message without a body.

POST method is used for execution of INSERT operation and the HTTP request message with body.

PUT method is used to execute the UPDATE operation.

DELETE method is used to execute the DELETE operation.

The header named ‘Content type’ present in the HTTP request message depicts the format of payload. This could be JSON, XML etc.

The next header named ‘Accept’ in the HTTP request message shows the expected payload format in the HTTP response. This could include JSON, XML, HTML etc.

  • Response Payload format- This format has one parameter and one sub element which include the response type and data (which may have zero or more parameters).
  • Failed Response Payload format- This format has one parameter and one sub element namely Response type and Messages. Messages may include a zero or more error messages. Here, the HTTP response message also has HTTP status codes which start from 100 and go up to 599. It is important to note that the payload refers to the body in HTTP response message and this is optional or depends on the error code. Also, the header ‘Content type’ in the HTTP response message depicts the payload format.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.