How to test an API using Postman ?

Last Updated : 23 Jan, 2026

API testing ensures that an Application Programming Interface (API) works as expected. Tools like Postman allow developers to send HTTP requests (GET, POST, PUT, DELETE, etc.), validate responses and automate test cases. This helps assess the functionality, reliability, performance and security of an API.

What is Postman

Postman is a widely used API testing and development tool that helps developers send HTTP requests, validate responses, and automate API testing through a simple interface.

  • Supports HTTP methods like GET, POST, PUT, and DELETE
  • User-friendly interface for building and testing APIs
  • Organizes requests using collections
  • Uses environment variables for dynamic data
  • Allows automated testing with JavaScript
  • Provides mock servers, monitoring, and team collaboration

Prerequisites: Download Postman.

Syntax of an API Request in Postman

<Request Method> <Request URL>

Example:

GET https://api.example.com/users

Step-by-Step Example: Testing an API

Let’s assume we have a Library API with the base URL:

https://library-api.postmanlabs.com

Step 1: Create a New Workspace

  • Open Postman
  • Click Workspaces -> Create Workspace
  • Name it Library API Testing
  • Click Creat

Step 2: Create a New Request

  • Click New -> Request.
  • Choose a request type (e.g., POST to add a new book).
  • Enter the URL:

https://library-api.postmanlabs.com/books

Step 3: Add Request Body

  • Go to the Body tab
  • Select raw
  • Choose JSON
  • Enter the following data:

{

"title": "To Kill a Mockingbird New" ,

"author": "Harper Lee",

"genre": "Fiction",

"yearPublished": 1960

}

Step 4: Send the Request

  • Click Send.
  • Check the Response window at the bottom.
  • If successful, you’ll see:
  • Status Code: 201 Created
  • Response Body with book details.

And then check the response in the "Response" window. You should be able to view book details. Now for API testing, first, go to the "Tests" tab.

Screenshot-(190)-(1)
Response window at bottom showing book details

Look for the code bracket icon. Select JavaScript Fetch. Write JavaScript code for fetch response is, like:

JavaScript
const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("api-key", "postmanrulz");

const raw = JSON.stringify({
    "title": "To Kill a Mockingbird New",
    "author": "Harper Lee",
    "genre": "fiction",
    "yearPublished": 1960
});

const requestOptions = {
    method: "POST",
    headers: myHeaders,
    body: raw,
    redirect: "follow"
};

fetch("https://library-api.postmanlabs.com/books", requestOptions)
    .then((response) => response.text())
    .then((result) => console.log(result))
    .catch((error) => console.error(error));

Step 5: Write Tests in Postman

  • Go to the Tests tab
  • Add the following code:

const id = pm.response.json().id
pm.collectionVariables.set("id", id)

  • Click Run to execute the test

This script extracts the id from the response and stores it as a collection variable for future requests.

Output: Since the API Testing was successful. It shows the response status and body.

Screenshot-(186)-(1)-(1)
The code 201 ishighlighted in green.

Common HTTP Status Codes in API Testing

Status CodeTypeMeaning
200SuccessOK
201SuccessResource Created
204SuccessNo Content
400Client ErrorBad Request
401Client ErrorUnauthorized
403Client ErrorForbidden
404Client ErrorNot Found
500Server ErrorInternal Server Error
Comment

Explore