A Postman Environment is a collection of variables that allows you to store reusable values such as API URLs, ports, tokens, and other configuration data.
A Postman Environment stores variables that can be reused in API requests.
For example:
base_url
api_token
user_id
Instead of writing the same values in every request, we can use environment variables.
An environment makes API testing easier when values change between different environments.
For example:
The API requests can remain the same while the variable values change.
An environment contains variables and their values.
Example:
base_url = http://localhost/api
The variable name is base_url and its value is http://localhost/api.
You can create an environment from the Environments section in Postman.
Give the environment a meaningful name.
Examples:
A clear name helps identify which configuration is currently being used.
During development, an API may run on a local computer.
Example:
http://localhost/api
This URL can be stored in an environment variable.
A development environment can contain values used by a development server.
Example:
base_url = https://dev.example.com/api
API requests can use this value instead of hard-coding the URL.
A production environment contains values used by the live application.
Example:
base_url = https://example.com/api
The same API requests can use this environment without changing every URL manually.
Postman environment variables can be referenced using double curly braces.
{{base_url}}/students
If base_url contains:
http://localhost/api
the resulting URL becomes:
http://localhost/api/students
Postman uses double curly braces to reference variables.
{{variable_name}}
Example:
{{base_url}}
This tells Postman to use the value stored in the variable.
A base URL is one of the most useful environment variables.
base_url = http://localhost/api
Then requests can use:
{{base_url}}/students.php
{{base_url}}/users.php
{{base_url}}/courses.php
Suppose the API endpoint is:
http://localhost/api/students.php
Instead of writing the complete URL repeatedly, create:
base_url = http://localhost/api
Then use:
{{base_url}}/students.php
An environment can contain multiple variables.
base_url
api_version
user_id
token
Each variable can store a different value.
You can store the API version in a variable.
api_version = v1
Then a URL can be written as:
{{base_url}}/{{api_version}}/students
This can make version changes easier to manage.
A user ID can also be stored in an environment variable.
user_id = 25
It can then be used in a request such as:
{{base_url}}/users/{{user_id}}
Authentication tokens can be represented by environment variables when testing protected APIs.
token = your_token_here
A request header could then use:
Authorization: Bearer {{token}}
The actual token value is taken from the selected environment.
When multiple environments exist, select the environment you want to use for the current API testing session.
For example:
Local
Development
Production
The selected environment determines which variable values Postman uses.
Suppose your API has two servers.
Local:
http://localhost/api
Production:
https://example.com/api
You can switch environments instead of changing every API request manually.
Collections and environments work together.
Collection
↓
{{base_url}}/students
↓
Selected Environment
↓
Actual API URL
This allows the same collection to work with different API servers.
Development:
base_url = https://dev.example.com/api
Production:
base_url = https://example.com/api
The request can remain:
{{base_url}}/students
Only the selected environment changes.
When developing a React Native application, the backend API may change between development and production.
Postman environments help test the different API URLs before connecting the mobile application to them.
React Native App
↓
REST API
↓
Postman Testing
Variables can also be used inside headers.
Example:
Authorization: Bearer {{token}}
Postman replaces the variable with its configured value when the request is sent.
Variables can also be used in query parameters.
{{base_url}}/students?course={{course}}
For example, if:
course = ADCA
the request becomes:
{{base_url}}/students?course=ADCA
Variables can also be useful inside request data.
{
"name": "{{student_name}}",
"course": "{{course}}"
}
This allows test data to be changed without rewriting the entire request.
Always check the selected environment when an API request does not work as expected.
Use clear environment names such as:
Student API - Local
Student API - Development
Student API - Production
Clear names reduce confusion when several environments are available.
Before sending an API request, check:
Environment: Student API - Local
base_url = http://localhost/api
api_version = v1
user_id = 10
course = ADCA
token = your_token_here
A request can use these variables like this:
{{base_url}}/{{api_version}}/students/{{user_id}}
Create Environment
↓
Add Variables
↓
Select Environment
↓
Create Collection
↓
Use {{variables}}
↓
Send API Request
↓
Check Response
This workflow makes API testing more organized and reusable.
Postman Environments allow developers to store reusable configuration values. They are particularly useful when working with multiple API servers or changing values such as base URLs, user IDs, courses, and authentication tokens.
Environment
↓
Variables
↓
{{variable}}
↓
API Request
↓
REST API
Question: How is a Postman environment variable usually referenced inside an API request?