Open In App

Postman Collections

Last Updated : 11 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Postman is the best tool when it comes to working with API. It comes with all the features, that can be useful for us with the APIs. Collections are one of those features that we can use for documentation, running the Tests, writing Pre-Request Scripts, and all. These all things are bundled up into the collections. Based on collections, we can create Mock Servers to show the behavior of API.

Creating a Collection

We can create a collection by giving it a name and then adding some API for our project. Postman gives us the templates of some collections which are pre-built. We just want to reuse them, modify to according to our requirements, and tailor the collections. Templates are given according to Roles, Use Cases, and Industries. With the help of these templates, we just need to add the functionality that we wanted in addition to our workflow.

Creating a collection

Templates of Collections

You can see what the collections contain before by just clicking it and if you find it useful you can use the Template. For this, I am going to use the REST API basics template and let’s see what collections contain and how to use them in the best way.

Template-Home-Page

REST API basics template

This is the Overview page of Collections where we write about our APIs and how a developer can use them in his applications. On the left side, all our APIs are listed with the method name and title of the API. In the top bar, we have some options for Share, Fork, Run and Save. Below that, there is a navigation bar in which options of Authorization, Pre-Request Script, Tests, Variables and Runs including overview options are given.

Diving into the Navigation Bar

So, there are a total of 6 options given and we will understand all of them one by one.

Overview

This is a description page which other developers can use before looking into the API’s. It gives the idea of what all the APIs are and how they can use them. You can paste pictures if you want for better explanation. We can give multiple links with which a developer can navigate and get a basic idea about the project or the documentation.

If you click on Complete Documentation, you will see the APIs with some description as shown below.

Complete-Documentations

Details of a API with Parameter it contains and the example of response body

So, this contains the Name and method at the top, then the URL for accessing the API. Below that, we can see some descriptions like where can we use this and then what will be the status code returned on different scenarios. It also contains what parameters we are passing and the structure of the body passing with the API.

Authorization

This is used for specifying the authorization for each request in collections. Rather than giving the same information as the JWT token in every request, we can give it over here and automatically it will be passed in all the APIs. Postman gives so many options for authorization including the OAuth 2.0 to Bearer Token but you can change the type of authorization for any one request if you want.

Authorisation

Authorization

Pre-Request Script

This script will execute before every request in this collection. You can use this tab for writing the scripts for Authentication setup, Dynamic Data Generation, Request Modification, Data Manipulation, Logging and Debugging and many more. All these things are applied to all the requests in the collections.

Tests

This is one of the important and best features of Postman. It allows us to write the test after the execution of the API. We can use it to check the status code, execution time and whether the response body contains some field or not. All this will be done once the request is returned.

Tests

Test Section and example of one test

This test is executed with each of the requests written in the collections and we can see their result in the test tab beside of response body.

Variables

These are the variables just like a programming language, where we assign the name to some value and use it in different places which makes the code more effective. Similarly in the Postman, we have so many things that we require at different locations like the URL and token for authentication.

Variables

Variables for the collections

Here we have two variables first is id and the second one is base_url. Also, there is an Initial Value and a Current Value.

  • Initial Value: This is the value that is stored on the Postman Servers, when we want to share the collections. Changing this value will change the value on the server.
  • Current Value: While the current value is the value, that is not stored on the server, it is a local value and changing the local value doesn’t affect the value on the server

Runs

This is a very interesting segment of collections. Over here, we can run the whole collections to check the functions to see whether the APIs are working fine or not. We can schedule the run, which means that we can set the time when all the APIs will run and the report or error will be logged and last is Performance Testing, which is used for testing the performance under the load and for checking the response time and at what rate the error is thrown.

In the image shown below, all the runs are listed and we can see them according to different filters.

Runs

3 types of Run

1. Functional Runs

This is the basic run, it will only run the APIs with parameters and the body and report the status code, time to complete the request, average response time and how many times the iterations of the run have been done.

Functional-Runs

Functional Run Report

We can see that the test that we had written earlier also passed for all the APIs that we were discussing.

2. Scheduled Run

In this section, we create a schedule on which the API will be executed. In this, we can set the name of the schedule with the frequency of the API to be executed. We can set the schedule to be executed on an hourly timer or on a weekly timer with the day and time when the schedule will run.

Schedule-Run

Scheduled Run

3. Performance Runs

This is very useful for performance testing of the collections. It includes the number of Virtual Users which will execute the API in parallel and duration for which the API should execute continuously. This is very useful because it gives us real-time access to the performance. After all, in real-time we will have thousands of users who are continuously accessing our APIs.

Performance-Run

Report of Performance Testing

We can see the report based on 20 Virtual Users with a time duration of 10 minutes. This report gives us the stats of Response time and also the rate of errors, total requests sent and the number of requests sent per minute.

Conclusion

These are some important and widely used features of the collections but these are not only features, there are other features like the Creation of Mock server Generation, Export the collection, Fork the Collections and have a look at changelog. These are the advanced features and it might be the case, that we don’t even require many of these features as developers. Though, feel free to have a look at them because knowing them will only increase the weapon in armor.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads