In Postman, an environment envelops variables meant to be reused in API requests. These variables store environment-specific information that will be automatically included wherever these variables are referenced. This turns the API requests flexible, reduces the probability of errors, and increases efficiency.
An environment is simply a collection of variables stored as key-value pairs. The key represents the variable name. The following example illustrates the concept of environments:
Environment | Variable | Value |
Production |
| https://api.agify.io/?name=production |
Development |
| https://api.agify.io/?name=development |
Testing |
| https://api.agify.io/?name=test |
Whenever we switch between these environments, the variable {{base_url}}
's value will change and be automatically reflected throughout the API requests, including this variable.
To foster a formal development life cycle, setting up different API environments in Postman is always better. Such segregation of environments will allow us to build custom requests based on the variables defined in these environments and easily switch between them without modifying our requests.
Environments can be exported as JSON files, imported, shared, duplicated, and removed.
Let's examine the environment's configuration in the Postman web version.
Kindly follow the steps listed below:
Log in to the Postman web version.
Select a workspace.
Click the "Environment quick look" button located in the top-right corner near the Environment Selector or press the "Create Environment" link as illustrated in the screenshot below:
Name the newly created environment; for example, Name it "Production" as shown below:
Name: This is the name of the variable.
Type: The “default” option shows the variable content in plain text. The “secret” option mixes up all workspace members’ initial and current values and is more appropriate for hiding sensitive info like passwords, tokens, and keys.
Initial value: Any collaborator with access to the Postman environment will have access.
Current value: The current value is only visible to the user.
The "Environments" sidebar provides access to all available environments. To activate an environment, select the "Set active" icon next to its name as displayed below:
Free Resources