Table of contents
1.
Introduction😇
2.
API 🖥️
3.
Building Blocks of Postman 🏗️📬
3.1.
Request 🙏🏻
3.2.
Collection 
3.3.
Environment
4.
Extraction of an authentication token
5.
Reading Links from Response 🧐
6.
Parameterize Requests in Postman
7.
Frequently Asked Questions
7.1.
What is setNextRequest in Postman?
7.2.
What is Newman in Postman?
7.3.
Why do we need Newman?
8.
Conclusion
Last Updated: Mar 27, 2024
Easy

Related Workflow in Postman

Author Sagar Mishra
1 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction😇

Postman is an API (application programming interface) development tool that allows building, testing, and modifying APIs. This tool contains almost all the features a developer could need. It can create HTTP requests (GET, POST, PUT, and PATCH), save environments for later use, and translate the API into code for different languages (like JavaScript and Python).

logo

In this article, we will learn the concept of Related Workflow in Postman along with API testing in Postman.

API 🖥️

The first topic of the "Related Workflow in Postman" series is API. Here, we will discuss the basic concepts of API. Let's start!

API (Application Programming Interface) is basically a set of procedures and functions that allow the development of apps. They gain access to the data and functions of different programs, services, or operating systems.

By giving all the required building parts for the programmer to assemble, good APIs make it simpler to create computer programs. Due to their ability to be combined and reused indefinitely to create new services, APIs are often likened to Legos.

Building Blocks of Postman 🏗️📬

The next topic of the "Related Workflow in Postman" series is Building Blocks of Postman. Here, we will discuss topics like Request, Collection, and Environment.

It is now quicker and easier to design and test APIs in Postman. Postman's most potent and practical aspects, such as requestscollections, and environments, can be easily created with a single click.

Let's take a quick tour of the Building blocks of Postman.

Request 🙏🏻

Any HTTP request can be made using Building blocks in Postman. Click Request and add a title and description to create a request. Choose a collection, then store the Request there. You can choose an existing collection or start a new one. After saving the Request, you can modify it in the builder by adding the URL, method, headers, and body.

Let's check the example screen of Request in Postman.

requests

Collection 

A group of different requests is referred to as a Collection, which you can then categorize into folders. Click Collection, give it a name, and a description, then click Create Collection. After building the collection, you can add folders for improved organization and then save requests there. 

collection

Environment

You often require various setups while working with APIs, such as your client Machine, the development server, or the production API. Using environments, you can modify requests. Click Environment and assign a name to it to build an environment. The variables you want to save as key-value pairs should then be added.

environment

Extraction of an authentication token

Our next topic in the "Related Workflow in Postman" series is the Extraction of an authentication token. Here, we will discuss how to extract a token from a login response.

We can extract the value of an authentication token from a login response body and pass in subsequent requests as 'Bearer Token' using the below commands:

According to the authentication server's response:

{ "accessToken": "foo", "refreshToken": "bar" "expires": "1234" }

 

The syntax for extracting the token value from the Tests tab is:

var jsonData = pm.response.json(); 
var token = jsonData.accessToken; 

 

We can set the token as a variable for future use by using:

pm.globals.set('token', token); 

 

The following needs to be provided to the headers part (see the key: value example below) in order to use the token in the new request:

Authorization:Bearer {{token}} 

Reading Links from Response 🧐

Our next topic in the "Related Workflow in Postman" series is the Reading links from the response. Here, we will discuss the topic along with codes.

At first, we have to give the sample links to the server for response. Syntax of the same is shown below:

{ 
	"links": [ 
	"http://sample.com/1", 
	"http://sample.com/2", 
	"http://sample.com/3", 
	"http://sample.com/4", 
	"http://sample.com/5" 
	] 
} 

 

To read the response, we have to follow the below points:

  1. Parse the response
  2. Check the response
  3. Iterate over the response

 

Now, let's understand all the steps using code:

// Parsing the response
var jsonData = pm.response.json();
// Checking the response
pm.test("Response containing the links", function () {
	pm.response.to.have.status(210);
	pm.expect(jsonData.links).to.be.an('array').that.is.not.empty;
});
// Iterating over the response
var links = jsonData.links;
links.forEach(function(link) {
	pm.test("Status code is 404", function () {
		pm.sendRequest(link, function (err, res) {
			pm.expect(res).to.have.property('code', 404);
		});
	});
});

 

Using the pm.sendRequest command, we have read the response, iterated over the links arrays, and submitted the request for each link.

Parameterize Requests in Postman

Our last topic in the "Related Workflow in Postman" series is the Parameterize requests in Postman. Here, we will discuss the topics in steps. 

Postman requests can be parameterized so that they can be executed with a variety of data sets. Variables and parameters are used to do this. The URL contains a parameter that is used to deliver additional data to the server.

Follow the below steps to parameterize requests:

Step 1: In the top right corner, click on the eye icon of the Environment dropdown in the Postman app.

Environment dropdown
 

Step 2: In the Global Section, Click on the Edit link.

global section

 

Step 3: MANAGE ENVIRONMENTS pop-up appears. In the VARIABLE box, type URL, and in the INITIAL VALUE field, you can type any URL. For example, https://www.codingninjas.com. Then select Save.

manage environment

 

Step 4: To move to the next screen, Click on Close. You can also change the Tab.

 

Step 5: Enter {{url}}/index.htm in the address bar of Http Request tab. Select the GET method and click the Send button.

request tab

 

Response

Once a request has been sent, the response will have the response code 200 OK filled in. This denotes a fulfilled request and the right endpoint.

response

Frequently Asked Questions

What is setNextRequest in Postman?

The source of your collection run is Postman's setNextRequest() scope. Any request, such as those inside folders, can be set as the next request when a collection is run in its entirety. If you run a folder, only that folder is the postman.setNextRequest() function's scope.

What is Newman in Postman?

For Postman, Newman is a command-line Collection Runner. You can use the command line to execute and test a Postman Collection directly. It is designed to be extensible so that you can integrate it with your build systems and continuous integration servers.

Why do we need Newman?

Running a group of tests directly from the command line is simple with Newman. This makes it simple to run Postman tests on systems without a GUI and enables us to run a set of Postman tests directly from most build tools.

Conclusion

We have discussed the topic of Related Workflow in Postman. We have seen topics like API, Building Blocks of Postman, Extraction of an authentication token, Reading links from the response, and Parameterize Requests in Postman. 

We hope this blog has helped you enhance your knowledge of "Related Workflow in Postman." If you want to learn more, check out our articles API TestingIntroduction to PostmanPostman to API Testing, and many more on our platform Coding Ninjas Studio.

But suppose you have just started your learning process and are looking for questions from tech giants like Amazon, Microsoft, Uber, etc. In that case, you must look at the problemsinterview experiences, and interview bundles for placement preparations.

However, you may consider our paid courses to give your career an edge over others!

Happy Learning!

Live masterclass