How to test an API using Postman ? (original) (raw)

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.

**Prerequisites: Download Postman.

Syntax of an API Request in Postman

**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

Step 2: Create a New Request

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

Step 3: Add Request Body

{

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

"author": "Harper Lee",

"genre": "Fiction",

"yearPublished": 1960

}

Step 4: Send the Request

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

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

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 Code Type Meaning
200 Success OK
201 Success Resource Created
204 Success No Content
400 Client Error Bad Request
401 Client Error Unauthorized
403 Client Error Forbidden
404 Client Error Not Found
500 Server Error Internal Server Error