What is a Collection in Postman?
A collection is a group of API requests organized into separate directories according to a logical order
How to create a collection?
To create a collection we can follow one of the methods.
- New -> Collection
2. Click on the plus icon
Now you will get into the following UI to create a collection.
Here we can give a name for the collection.
Now I have created Collection2. Let’s see fields in the collection.
- Authorization — If we have common parameter values across all API requests inside the collection authorization is important.
Eg: Same authorization details
- Pre request scripts — Any pre request script that should be run prior to REST API request
- Tests — Need to run parallel to the request
- Variables — Common values which can be used inside the collection
In the collection UI when we click on more options we can see options such as share collection, run collection, edit, add request, add folder, monitor collection, mock collection, create a fork, view documentation, rename, duplicate, export, manage roles, remove from workspace and delete.
When we click on “Monitor collection” this is the UI that we get. Here in this option we can run the collection periodically.
When we click on “Run option” we will get the runner window as follows.
How to create a folder inside a collection?
By clicking on “Add folder option” we can simply create a folder as follows.
How to arrange requests inside a collection?
By clicking on more options on the folder, we can simply create a request inside the folder.
Now our folder structure is as follows.
How to run a collection?
Now I have created two simple requests in Collection2.
Before running the collection make sure to save all requests that we added. Then we can click on view more -> Run collection
Runner window is as follows.
Here we can see the added requests in the collection. If we want to choose some selected requests to run we can simply check or uncheck the relevant check box of the request.
Here we have some more options such as environment, iterations, delay and data. If we want to run a collection many times we can enter the number of times to be run. And if we want to keep delay in between requests we can enter a delay time.
To run the collection we can click on the “Run collection1” button.
Here we can see the results of the collection that we run. We have view summary, run again, new and export results options there. If we click on the export results button we can get the results in JSON format.