Create, Use, and Run Postman Collections
Postman Collections are a powerful feature that enables users to organize and manage API testing and development. Collections consist of requests, which are APIs with a request and response format. In this article, we study the creation, utilization, and execution of Postman Collections with examples.
Creating a Postman Collection
1. Open Postman
Launch the Postman application.
2. Create a New Collection
- Click on the âCollectionsâ tab in the left sidebar.
- Click the âNew Collectionâ button.
- Enter a name and optional description for your collection.
You can create a new blank collection like this:
or Choose a template for the collection like this:
Here, we have selected Rest API Basics as the template, and what you see is a loader creating template in progress mode. This is how it looks like once the creation is completed.
It has by default all the four requests available for you to edit and duplicate to save time.
3. Add Requests to the Collection
- Click on your newly created collection.
- Click the âAdd Requestâ button.
- Enter a name for the request and specify the HTTP method (GET, POST, etc.).
- Define the request URL and any necessary parameters.
- Click âSaveâ to add the request to the collection.
Remember to always name your APIs depending on the resource you are accessing, how you are accessing and what action you are going to perform.
In the image show below, we are trying to fetch the user details by userId. So the route pattern is like
<Server_Url>/<resource>/<action>/<any_params>
Every one have their own internal standards or rules behind naming the routes but this is something that is most widely used among the developers in general.
Another way to create a request is by using Import button available on top.
Copy the following lines of code and click on import button. Then you will be able to see a dialog that gets opened that says paste cURL. Paste the below code in that text box and wait:
Javascript
curl --location 'https://api-m.sandbox.paypal.com/v1/oauth2/token' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --header 'Authorization: Basic QVV2OHJyY19QLUViUDJFMG1wYjQ5QlY3ckZ0M1Vzci12ZFVaTzhWR09ualJlaEdIQlhrU3pjaHIzN1NZRjJHTmRRRllTcDcyamg1UVVoekc6RU1uQVdlMDZpb0d0b3VKczdnTFlUOWNoSzktMmpKLS03TUtSWHBJOEZlc21ZXzJLcC1kXzdhQ3FmZjdNOW1vRUpCdnVYb0JPNGNsS3RZMHY=' \ --data-urlencode 'grant_type=client_credentials' \ --data-urlencode 'ignoreCache=true' \ --data-urlencode 'return_authn_schemes=true' \ --data-urlencode 'return_client_metadata=true' \ --data-urlencode 'return_unconsented_scopes=true' |
This will create a new request and gives you the rename and save options, once this is successfully processed.
4. Repeat for Additional Requests
Repeat the process to add more requests to the collection if needed.
Using a Postman Collection
1. Access Collections
In the âCollectionsâ tab, youâll see a list of your collections.
2. View and Edit Requests
- Click on a collection to view its requests.
- Click on a request to view and edit its details, including the request URL, parameters, headers, etc.
3. Organize and Group
Organize requests within a collection using folders to structure your API tests logically.
Here is the public collection available over postman website showing how to organize APIs by collection and folder level. This serves as a good example for organizing the requests in postman collection
Running a Postman Collection
1. Open Collection Runner
Click on the âRunnerâ tab in the left sidebar.
2. Select Collection
Choose the collection you want to run from the dropdown list.
3. Run Collection
Click the âRunâ button to execute all requests in the collection.
You can run all the tests in a folder and all the responses will be visible one by one
Then, a new view will be visible on the screen as shown below. Here you can choose to run manually or schedule runs at regular intervals.
4. View Results
- Postman will execute each request sequentially and display results.
- You can view response details, status, headers, and more as shown below.
This is how it looks after all the APIs in the folder has been run
Conclusion
Postman collections are powerful tools for maintaining and automating API testing and development workflows. By creating, using, and running collections, you can streamline your testing process, collaborate with team members. Regularly exploring new features and staying updated on Postman plans ensures optimal utilization of this versatile tool.
Contact Us