DEV Community

Cover image for Using Postman like a PRO with these tricks ๐Ÿ˜Ž
Jonathan Brizio
Jonathan Brizio

Posted on

Using Postman like a PRO with these tricks ๐Ÿ˜Ž

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);
Enter fullscreen mode Exit fullscreen mode

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.

Example

๐Ÿ’ฌ Sharing your knowledge

And you, what other trick knows with Postman? Post a comment below.

Top comments (15)

Collapse
 
liyasthomas profile image
Liyas Thomas • Edited

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:

Collapse
 
jonathanbrizio profile image
Jonathan Brizio

Hi Liyas, thanks for you words.
I will take a look, thanks for share with us.
Keep rocking!๐Ÿค˜

Collapse
 
dmdesai_ profile image
Div

How can I create test-cases and automate it with Jenkins using Postwoman?

Collapse
 
pavelloz profile image
Paweล‚ Kowalski

Usually you would use test framework for that, not http client.

Thread Thread
 
liyasthomas profile image
Liyas Thomas • Edited

Yeah! There's lot of amazing tools like Cypress, Jest, Ava etc.. Postwoman uses and suggests Cypress because it's community is amazing.

Collapse
 
liyasthomas profile image
Liyas Thomas

A cli is in WIP. Will rollout as soon as possible.

Thread Thread
 
dmdesai_ profile image
Div

Okie. But I don't think it's right to say alternative to Postman. Postman is handling much more than just an API Client.

Thread Thread
 
liyasthomas profile image
Liyas Thomas

True. We're "building" a faster alternative then โšก๐Ÿ‘

Thread Thread
 
dmdesai_ profile image
Div

That's convincing :) ๐Ÿ‘

Collapse
 
hey_yogini profile image
Yogini Bende

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!

Collapse
 
jonathanbrizio profile image
Jonathan Brizio

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!

Collapse
 
kj2whe profile image
Jason

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...

{
    //  Blah blah blah...
    "Property1": "value",
    "Property2": "other value"
}

but then I realized, you know, you can save those comments in the Add a description part underneath name??

oh well... :)

Collapse
 
karataev profile image
Eugene Karataev

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.

Collapse
 
francofadini profile image
francofadini • Edited

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

Collapse
 
jonathanbrizio profile image
Jonathan Brizio

Yeap, totally agreed with you Franco. Mocks are really useful to speed up our development.