API Testing Tutorial Part 13 – What is a Payload in an API?

As a part of our API Testing series, in this post, we will learn about an important terminology of API called “Payload”.

A Restaurant

Take a real-time scenario. A typical example of a Restaurant. A restaurant serves foods of different cuisines. It may be north Indian, south Indian, Chinese, Italians, etc. Everyone who visits the restaurant will be served on their choice. But there will be a pattern:-

  1. Visit restaurant
  2. Connect with a Waiter.
  3. Give instructions to the waiter.
  4. You will be served as requested food.

The waiter works on specific instructions. If you want a north Indian cuisine food you need to give instructions to a waiter or if you want a south Indian cuisine food you need to give instructions to the waiter. A waiter can not decide what food you want. Similarly, an API works on instructions or Payload.  Foods are resources, a waiter is an API and instructions are payloads at high levels here. So how you will be served depends on what you instruct.

When we launch the Facebook URL then we need to log in with our specific credentials. In response, the Facebook server will return back with the requested user’s profile details. It is a two-way process. Payload as request and payload as a response. Request payload is sent from client to server and response payload is sent from server to client.

There are many ways of providing payload to an API. It may be a JSON, XML, HTML, TEXT, etc but all serve the purpose of giving instruction to an API with different representations.

If we see a Create Booking API of RestFul Booker, you can see how this accepts the same information in two different formats.

JSON Format

XML Format

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappyLearning

Find all Selenium related posts here, all API manual and automation related posts here, and find frequently asked Java Programs here.

Many other topics you can navigate through the menu.

Leave a Reply

Your email address will not be published. Required fields are marked *