Open In App

How to Perform POST Request in Postman with Test Validation?

Improve
Improve
Like Article
Like
Save
Share
Report

Postman is an API(application programming interface) development tool that helps to build, test, and modify APIs. Almost any functionality that could be needed by any developer is encapsulated in this tool. It is used by over 5 million developers every month to make their API development easy and simple. It has the ability to make various types of HTTP requests(GET, POST, PUT, PATCH), save the environments for later use, and convert the API to code for various languages(like JavaScript, and Python). For getting started with this, we need to install the postman in our system.

Installation

Open this link https://www.postman.com/downloads/ and download the Postman.

 

After completing the download install the software in the system. In this article, we are going to POST the data using the URL “https://reqres.in/api/login” and write the Test validation script to run the tests for API.

POST Method

In the POST method, we are passing some data to the API. In this example we are sending the email and password for login API, if this is valid we will receive a token for login.

Steps for creating the POST method:

  1. Create a new workbook
  2. Create a Collection in that workbook.
  3. After creating the collection, now create a POST method into it.
  4. Add the URL.
  5. Move to the Body tab and select the option raw.
  6. After that, choose JSON from the dropdown.

Now, we have to enter the valid username and password in the JSON format in the body.

 

JSON Data:

“email”: “eve.holt@reqres.in”,
“password”: “cityslicka”

If the mail and password are valid we get the token as a response and status code as 200.

 

otherwise, we will get an error.

 

Adding Test validation

  • Now navigate to the tests tab.
  • After that an example for writing a test to this POST request, we have to check the response code is 200, and check the response body has the “token” present in it.

tests[“Checking response code”]=responseCode.code==200;
tests[“validating token presence”]=responseBody.has(“token”);

After the tests are written save the collection and now run it by clicking the send button.

 


Last Updated : 23 May, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads