Postman Environments

October 13, 2016

Postman is a great project to work with APIs. If you aren’t already using it, then you should take a look right away.

When you use Postman, at some point you will probably run into the problem of switching between development and production APIs. For example, I have a project called Python Jobserver with four endpoints.

In this example, the API points to my development server on localhost.

What if I want to test the API on my production server? I could manually switch the URL to my production server like this.

But you don’t want to manually switch back and forth. You could copy the entire project and rewrite all the endpoints, but that’s really cumbersome too.

There is a much better solution to this in Postman, called Postman Environments. With Postman Environments, you can declare variables that are scoped to just the environment. So you can make the url of your development and production server a variable and switch between environments to test the same APIs on different endpoints without changing the project.

Let’s try this. I create an environment by clicking the gear icon in the top-right and selecting Manage Environments.

I select Add and add an environment called Dev. I declare a variable url and its value is the location of my development server.

Repeat for the Production environment. You can see the same variable url but with a public IP associated with the url instead.

Now I can use the variable in the request with {{url}} . I switch environments at the top-right.

Awesome. You only have to maintain one project, and you can switch your environments easily to test your APIs if they are hosted in different places. Keep in mind you can also share your environments in Manage Environments along with your projects that use variables.