Select Page
API Testing

A Wall-to-Wall Postman Guide for API Testing

Looking for a guide to perform Get, Post, Delete requests and create Collections in Postman? Our Postman Guide covers it all.

A Wall-to-Wall Postman Guide for API Testing

Postman is an API (Application Programming Interface) development tool that allows users to perform GET, POST, PUT, DELETE, and many other requests to the web service API. Postman allows you to manually test your APIs in both its desktop and web-based applications. However, it also has the ability to automate these tests by writing JavaScript assertions on your API endpoints. As one of the best QA companies, we always thrive on using the best tools for our projects, and Postman has become one of our go-to tools when it comes to API testing. So in this Postman Guide, we will be exploring how to perform the above said requests like Post, Request, and so on. But before we proceed further, let’s have a brief introduction to API testing.

What is API Testing?

API testing is a type of software testing where application programming interfaces (APIs) are tested to determine if they meet the expected functionality, reliability, performance, and security levels. It only concentrates on the business logic layer of the software architecture.

API Testing - Postman Guide

Some of the important components in Postman

  • Pre-Request Script:

Users will be able to write a script to manipulate the data being sent with the request. The pre-request script will run before the request is sent.

  • Tests:

This is the test editor where the users can configure the test cases that are being validated once the request has been fulfilled.

  • Environment:

The environment in postman is a set of key-value pairs which is used to set dynamic values.

  • Collections:

A group of requests will be displayed under collections, and it can be used to organize and keep track of related requests.

Postman Guide to create & run the First API Request:

First and foremost, we have to create a new workspace and click on the New option under ‘File’, and then select ‘Request’.

Creating API request and running in Postman Guide

Enter the name as ‘GET Request’ and then click on + NEW COLLECTION. Following which we will be able to assign a suitable name for the collection.

Once we click on Save, the collection name will be displayed with your API in it. Now that we have prepped everything, let’s make the first API call by following the below steps,

We have to enter the URL in the address bar and click on the ‘Send’ button to see the response.

The response will include details such as the status code, time, size, headers, and cookies alongside the Body.

Response Image

Status Code

So if you take a look at the above image, the HTTP status code is shown to be “200 OK”, which means that everything has worked as expected and that our request is successful.

Time

Right beside the status code, we can see that the time taken to complete the request is 509 ms.

Size

The other available parameter is the size of the requested data, we can see that size is mentioned to be 1.92 KB in the above image.

Note:If we hover the mouse over the time and response values, we will be able to view more details

To save this response, we can simply click on the ‘Save Response’ option.

As stated above, we can also see the body, which is an HTML file in the image. Clicking on the ‘Preview’ option under the body will enable us to view the body in HTML format.

We can click on ‘Cookies’ to view the session-related information and on ‘Headers’ to view other details such as date, content type details, etc.

So by following the above instructions, we have successfully made our first request! Now let’s find out how to send a post request in Postman.

Postman Guide to send a Post Request:

Post is one of the HTTP methods that can be used to add new resources like a webpage and so on. So if we want to create and add a new user to the database, we can utilize the Post request. Likewise, we can also use Post requests for form submissions, authentication requests, and so on.

Let’s see how Post request works:

In Postman, we have an endpoint that responds back whenever we send a request. So, now we are going to send a particular key-value pair in the JSON format to a server.

First, we have to set the HTTP Method to POST.

Next, we have to mention the URL in the address bar.

In the Body tab of the request editor, we should select the ‘Raw’ option and then select JSON from the dropdown list.

We have chosen Raw with JSON as it is one of the most commonly used Post Requests.

So enter the REQUEST in the Body and click on ‘Send’.

Post Request working - Postman Guide

We can see that the user has been created in the above image. In addition to that, we also have the same type of information that we saw earlier that includes status code, time, and so on.

But this time around, we have the status code displayed as 201, which implies that the request has been created.
Click on ‘Save’ to save this request.

‘POST REQUEST’ can be used to add a set of data into the server database. But it is crucial to make sure that the fields are filled with the correct data type, as any incorrect data will result in a 400 Bad Request.

Postman Guide to send a DELETE Request:

Previously, we saw how to send a post request in which we created a user and sent a body. Now let’s see how we can delete a request in Postman. We can use the DELETE HTTP Method to delete an existing record of a user in a database. The expected response in the Status for this is 204.

So primarily, we would have to set the HTTP Method to DELETE, then mention the URL in the address bar, and also mention the final endpoint.

Once the above actions have been completed, we can go ahead and click on ‘Send’.

Expected Report

So as expected, we have the Status Code shown as 204, which denotes that the particular resource has been deleted.

But what if the user has some additional parameters? We can pass query parameters and add them to the body section for deleting those resources as well.

Collections

Collections are nothing but a group of requests grouped into a folder. The simplest example of this would be the way we organize the files on our computers or mobile phones. Let’s say we have multiple files of different formats like text files, audio files, video files, etc. We most probably would create new folders and segregate all the files based on their format.

In the same way, we can create different groups using POSTMAN, and each group can have its own type of request. In addition to having the option to create a collection, we will also be able to share this collection with the team members and encourage healthy collaboration. The other advantage is that since we can share the collection, we will also be able to perform various actions like assigning roles, documentation, mock servers, monitors, etc.

Postman Guide to create a collection:

Now that we have seen the purpose of collection, let’s find out how to create one by making use of the following steps.

Click on the ‘New‘ option, then click on ‘Collection’, and enter the Collection Name. We will be able to click on ‘Create’ once we have also added the description of the collection.

How to create a collection - Postman Guide

Now we can see that we have several options like Run, Share, and so on displayed.

Here we can click on ‘Add Requests’, or replace any existing requests.

Once we click on ‘Run’, a new window will be opened, enabling us to run the collection by clicking on ‘Run My Collection’.

So now we are able to see results for all the requests under the collection, making it evident that we can save an ample amount of time by running multiple requests at a time.

Results of Collection reports

We can click on the ‘Run Again’ option to rerun the collection. Following this, we can click on ‘Export Results’ to export the results as a JSON file. If you take a look at the below image, we can understand that it can be downloaded as well.

Exporting Results in Postman Guide

Different features of collections

• We can add the collections to favorites.

• It helps users share & assign the roles, create fork & pull requests, and also merge changes.

• We can create a duplicate of collections and export them.

Environment in Postman

It is very important to create distinct environments where one is dedicated for testing, one for development, and another for production. An environment is nothing but a set of variables or key-value pairs which we can be used in our requests. We can also change the value of the variables to pass the data between requests and tests. But how we do create an Environment? Let’s find out.

Postman Guide to create an Environment:

1. First, we have to click on the ‘Environments’ option.

2. Then we have to click on the ‘Add’ icon.

3. We can now enter the Environment name.

4. Followed by which we can enter the variable name to use it with the request.

The initial value is shared with your team when you share the variable in a collection as it will be shared with the collaborators who have access to the environment.

How to create an environment

The current value is always used when a request is sent as they are never synced to Postman’s servers. If left untouched, the current value will automatically be assumed as the initial value.

Click on ‘Add’ to create the environment. Once the environment has been created, users can share, copy or even download them if needed.

Global variables in Postman

Global variables allow users to access data between collections, requests, test scripts, and environments. Global variables are not dependent on any environment, making them available for all the requests. They are available throughout the workspace. But on contrary, local variables are available only in particular environments.

When to use Global and Local Variables

When we have multiple key-value pairs which do not depend on any environment, we can make them a Global variable.

Local variables can be used when we have key-value pairs which will change or differ between the environments.

Conclusion:

We hope you have enjoyed reading our Postman Guide for API Testing, as Postman is an effective tool when it comes to API testing. We have just seen the tip of the iceberg here, as these are the most important and basic functionalities every tester must know. As a leading test automation company, we have used Postman in various projects and have always been pleased with its performance. So one can always explore the many more useful functionalities that Postman has to enhance their API testing skills.

Comments(0)

Submit a Comment

Your email address will not be published. Required fields are marked *

Talk to our Experts

Amazing clients who
trust us


poloatto
ABB
polaris
ooredo
stryker
mobility