Basics of API Testing Using Postman

Last Updated : 20 Jan, 2026

Postman is a tool that can be used for API Testing. It a widely used API testing tool that simplifies this process by providing a user-friendly interface for sending requests, validating responses, and automating test scripts.

CRUD Operations with Postman

In web development, CRUD operations represent the four basic actions that can be performed on data:

  • Create: Adds new data (POST).
  • Read: Retrieves existing data (GET).
  • Update: Modifies existing data (PUT).
  • Delete: Removes data (DELETE).

Setting Up Postman

To get started with API testing in Postman:

  • Download and install Postman: You can install Postman from Postman's official site.
  • Create a New Request: Open Postman and click the + button to create a new request.
  • Choose HTTP Method: Select the HTTP method (GET, POST, PUT, DELETE) from the dropdown next to the URL bar.
  • Enter the Request URL: Enter the API endpoint URL you want to test.
Screenshot-2025-01-22-170804
Setting Up Postman

Example: Testing CRUD Operations with the Pet Store API

We will use a publicly available Pet Store API to demonstrate CRUD operations. The Pet Store API allows you to manage pet data, including adding, retrieving, updating, and deleting pets.

1. GET Request: Retrieving Data

A GET request retrieves data from the server.

Endpoint: GET /pet/{petId}

To fetch details of a pet, replace {petId} with the actual pet ID (e.g., /pet/1).

Steps in Postman:

  1. Set the method to GET.
  2. Enter the URLhttps://petstore.swagger.io/v2/pet/{petId}and replace {petId} with the pet’s ID (e.g., /pet/1).
  3. Click Send.
Set the method to GET.
Set the method to GET.

If the pet exists, the server responds with a 200 OK status and the pet's details. If the pet is not found, you will receive a 404 Not Found status.

2. POST Request: Adding New Data

A POST request adds new data to the server.

Endpoint: POST /pet

To add a new pet, use the following JSON in the request body:

{
"id": 12345,
"name": "Doggy",
"status": "available"
}

Steps in Postman:

  • Set the method to PUT.
  • Enter the URL https://petstore.swagger.io/v2/pet.
  • Go to the Body tab, select raw and choose JSON format.
  • Paste the updated JSON data.
{
"id": 6789,
"category": {
"id": 1,
"name": "dog"
},
"name": "doggie-postman",
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}
  • Click Send.
POST Request: Adding New Data
POST Request: Adding New Data

A successful update will return a 200 OK status.

3. PUT Request: Updating Data

A PUT request updates existing data on the server.

Endpoint:PUT /pet

To update details of a pet, provide the updated pet data in the request body.

Steps in Postman:

  • Set the method to PUT.
  • Enter the URL: https://petstore.swagger.io/v2/pet.
  • Navigate to the Body tab, select raw, and choose JSON format.
  • Add the updated pet data in the body, e.g.:
    {
    "id": 6789,
    "category": {
    "id": 1,
    "name": "dog"
    },
    "name": "doggie-postman-updated",
    "photoUrls": [
    "string"
    ],
    "tags": [
    {
    "id": 0,
    "name": "string"
    }
    ],
    "status": "available"
    }
  • Click Send to update the pet details.
PUT Request: Updating Data
PUT Request: Updating Data

4. DELETE Request: Removing Data

A DELETE request removes data from the server.

Endpoint: DELETE /pet/{petId}

To delete a pet, replace {petId} with the actual pet ID.

Steps in Postman:

  1. Set the method to DELETE.
  2. Enter the URL https://petstore.swagger.io/v2/pet/{petId}.
  3. Click Send.
DELETE Request: Removing Data
DELETE Request: Removing Data

The server will respond with a 200 OK or 204 No Content status on successful deletion.

Key Postman Features for API Testing

1. Collections

Collections allow you to organize related API requests and make your tests reusable and shareable.

Steps to create a collection:

  1. After creating a request, click Save.
  2. Assign the request to a new or existing collection.
  3. Use the collection to organize and execute multiple API requests.
saved Collections
saved Collections

2. Automated Testing with JavaScript

Postman supports writing automated tests using JavaScript, which can be executed after a request is sent. This helps to validate API responses in an automated manner.

Example Test:

pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});

This test checks if the response status code is 200.

3. Variables

Postman allows you to define variables to make your requests dynamic, such as for base URLs or authentication tokens.

Defining variables:

  • You can define variables in the Environment or Collection settings.
  • Use variables in the request URL like {{baseUrl}}/pet/1.

Best Practices for API Testing

1. Understand the API

Before testing, review the API documentation to understand the available endpoints, parameters, and response formats. This helps you craft effective tests and ensures you test all required functionality.

2. Verify Status Codes

Always check the status code to ensure that the request was processed correctly:

  • 2xx: Success (e.g., 200 OK, 201 Created).
  • 4xx: Client errors (e.g., 400 Bad Request).
  • 5xx: Server errors (e.g., 500 Internal Server Error).

3. Validate Responses

Ensure that the response body, headers, and response time are correct. Postman provides an easy way to validate these aspects using assertions in the test scripts.

4. Use Collections for Organization

Organize related API requests into collections for easier access and testing. Collections also support running tests in a sequence, making your testing process more streamlined.

Use Collections for Organization
Use Collections for Organization

5. Monitor Response Times

Ensure that the API responds within acceptable time limits. Postman allows you to monitor response times to ensure performance is not degraded.

Comment

Explore