In these last months, I learn a lot about this great tool that allows me to speed up and optimize my workflow reducing time on repetitive tasks.
If you're new with this tool, I recommend it before to read the entire documentation to look at the features and practice with some real cases.
๐ Setting environment variables automatically
So, let's start with my favorite trick. This is a script to be executed each time that copies the result of the petition and saves it into environment variables. This is great when you need to specify an authentication token that expires at a certain time.
var data = JSON.parse(responseBody);
pm.environment.set("Access-Token", data.access_token);
With that code, you're copying to your environment variable "Access-Token" the value obtained after executing the request. This script avoids copy and pastes values manually in your environment variables. In this way, you only need to invoke that variable to get the value in the authentication input or somewhere.
๐ Replicating an entire request
Another common trick is that it allows reproducing a request. Let's say we want to reproduce the same request when access to Coindesk to obtain the price of the bitcoin.
Open the browser development tools on Chrome. Then, go to the "Network Tab" and filter the requests desired. Right-click the one you are interested in, and select "Copy as cURL". Now we have the cURL, go back to Postman and click on the top-left of the screen the button "Import", and choose "Paste Raw Text" tab. Paste what you copied, and press Import. Now press "Send" and the request would be executed directly from your client.
๐ฌ Sharing your knowledge
And you, what other trick knows with Postman? Post a comment below.
Top comments (15)
This is helpful ๐
We're building 100% Open sourced (6,000+ stars on GitHub), free, online alternative to Postman.
It's named Postwoman. (postwoman.io)
Read more about it here:
Launching Postwoman v1.0 ๐ฝ - free, fast & beautiful alternative to Postman ๐
Liyas Thomas ใป Nov 5 ใป 4 min read
Hi Liyas, thanks for you words.
I will take a look, thanks for share with us.
Keep rocking!๐ค
How can I create test-cases and automate it with Jenkins using Postwoman?
Usually you would use test framework for that, not http client.
Yeah! There's lot of amazing tools like Cypress, Jest, Ava etc.. Postwoman uses and suggests Cypress because it's community is amazing.
A cli is in WIP. Will rollout as soon as possible.
Okie. But I don't think it's right to say alternative to Postman. Postman is handling much more than just an API Client.
True. We're "building" a faster alternative then โก๐
That's convincing :) ๐
One of my favorite tricks is to save the URL of API in a postman collection variable. In our current project, we use a temporary API link that changes with every deployment, so we can just copy-paste that URL into the variable and use the same for all APIs in a collection.
This is kind of similar to your first trick, but yes, that does save a lot of time and extra effort!! And thanks for these tricks. Got to learn something new!
I use that at diary too.
Another trick is duplicate tabs when you need to replicate the same config for a new one.
Thanks for your words Yogini!
Thank you for the automatically setting of the environment variable, didn't know that was a thing. I was gonna add Did you know you could put comments in your json body like so...
but then I realized, you know, you can save those comments in the Add a description part underneath name??
oh well... :)
Thanks for the tip with env variables, I didn't know that ๐
I really like postman collections. It helps to organize API requests with predefined
parameters in groups for instant access and easily share them with co-workers.
Mocking is an other great feature ! I was able to mock an entire API. This allows me to develop a full app without the need of the backend at all
Yeap, totally agreed with you Franco. Mocks are really useful to speed up our development.