Environments in Postman
Environment is a set of key — value pairs in postman.
Before moving into the environment let’s add a post request for user registration inside Collection1, POST folder.
Request URL: https://reqres.in/api/register
Now let’s add header parameters and click on the save button before running. Once you run, you will get the token as follows.
When we work with real time and real world APIs we have to test APIs in multiple environments. They will depend on different endpoints, user names, passwords etc with different values. Some sets of values may vary and others may not change. So the values that are changing can be taken as a group and can be set to the environment.
How to create an Environment
Click on new button -> Environment
Or else we can create an environment by clicking on the drop down icon as follows.
Now in the new environment “Env1” let us create new variables as follows
Let’s set values for those variables as follows.
And we can refer to the values in the header section by the variable names as follows.
By selecting the environment from the drop down icon we can set variables for that environment. This will reduce the re-work.