Open In App

How to test an API using Postman ?

API testing is a software testing type that tends to validate the application programming interfaces. As per Postman API, API testing is confirming that an API is working as expected. It sends requests to an API and monitors the responses to check its behavior to assess the functionality, reliability, performance, and security of an API. It is usually considered to be a crucial part of the API development lifecycle.

What is Postman API?

Postman recently ranked on top for best API Platform, by G2 in its 2023 Spring Reports. It is easy and user-friendly and offers various courses and projects. To use it, one must register in the Postman platform. As per Postman, it is an API platform for building and using APIs that simplifies each step of the API lifecycle and streamlines collaboration so one can create better APIs. It is trusted by over 25 million users worldwide. It has a friendly community too and allows API testing with REST.

History of Postman:

Just like every origin story, the origin, purpose, development till date has many theories but web based APIs tend to be more recent and the example can be Google Maps, something we use pretty often. Postman API was created by Abhinav Asthana, Ankit Sobti and Abhijit Kane in Bangalore, India (2012). Firstly, it was developed as a plugin for Google Chrome, then a rich client, and finally a thin client and now, Postman Inc., originally from India, has its headquarters in San Francisco.

Syntax:

<Request method> <Request url>

Example of API Testing using Postman

How about a bookstore or maybe Library API? We'll test that in this example. Firstly, get acquainted with the basics of Postman API and API testing fundamentals first like HTTP methods, mostly. You need to create an account in the Postman API platform.

Screenshot-(189)-(1)

Enter any book details in the code snippet

Screenshot-(190)-(1)

Response window at bottom showing book details

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));
const id = pm.response.json().id
pm.collectionVariables.set("id", id)

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

Screenshot-(186)-(1)-(1)

The code 201 ishighlighted in green.

According to Postman API, the table contains the status code that it offers.

Code Range

Description

Example

2--

Success

  • 200 - OK
  • 201 - Created
  • 204 - No content but OK

3--

Redirection

  • 301 - Moved/Changed path

4--

Client Error

  • 400 - Bad request
  • 401 - Unauthorized
  • 403 - Not Permitted
  • 404 - Not Found

5--

Server Error

  • 500 - Internal server error
  • 502 - Bad gateway
  • 504 - Gateway timeout

Key Features:

Advantages:

Disadvantages:

Article Tags :