Wait a minute mister Postman, or Postman environments

Postman is a tool that facilitates web application testing by sending requests and allowing you to inspect responses and whatever comes with them (response codes, headers, cookies etc). Yes I know that really (like, really) cool devs use curl or better yet, httpie (which is really cool, seriously, try it). But sometimes you just want to have a nice UI which you can actually show to a QA or a product manager and don’t pretend that you are that egg-headed guy doing some dark magic that’s spitting text into your console in response to you spitting out the commands that make no sense. Or you are just tired of trying to remember those commands and parameters yourself (but of course, a real dev would never acknowledge that, right?…).

This is how the cool kids do it (matrix gif)

This is how the cool kids supposedly do it.

Whatever the reason for you to use it, Postman can improve your life a bit.
And Postman environments can improve your overall Postman experience.

I was surprisingly slow to adopt the environments feature, though it is pretty basic. However, having tried it, I now swear by it. Because usually your web application runs it at least – at least! – three different environments: developer, staging (or test) and production. And for all of them, the requests you send will be pretty much the same, except for the root URL and the parameters or headers you are sending. Enter environments.

Before I started using the environments, I just copied the requests and saved them with different names or in different Postman collections. But imagine that you have an app with five – yes, just five – endpoints. And three environments, because we agreed that usually there’s at least that many. So, you create five requests with repeating values. Then each of them has to be copied twice, into different collections. Then you have to go through those ten copies and change relevant values manually. That’s a lot of work, isn’t it? That’s a lot of stupid unnecessary work that I have been doing.

I’m going to show how simple it is to use the environments once you have created them.

So, suppose you have an environment (which you have just created by simply clicking a gear icon on the upper right in Postman and selecting Manage Environments from the context menu and then clicking Add). And you have two values in the environment (which I of course so cleverly photoshopped out of the pics, but you will have values in place).

Variables in your environment

Variables in your environment

And then when you want to use the variables you created in the environments in your requests, you have just to enclose them in double braces (curly brackets) like {{this}}. And in some places, when you open the double braces, Postman will even help you out.

Autocomplete when you use variables

Autocomplete when you use variables

So, the complete finished request would look like this.

Request window with variables

Request window with variables

And notice that this screenshot is now much safer to share if you need to! You don’t give out any sensitive information.

And how do you select the environment? Why of course. There is this little handy selector on the top right.

Postman environment switcher

This one to the left from the eye and gear icon.

You can also share environments as described here. However, in that case it is usually recommended to first remove sensitive informations (tokens etc.) from them.

So, this is just one more small thing that makes a dev’s life just a little better. Have fun!


About Maryna Cherniavska

I have productively spent 10+ years in IT industry, designing, developing, building and deploying desktop and web applications, designing database structures and otherwise proving that females have a place among software developers. And this is a good place.
This entry was posted in Productivity, Programming and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s