Environment
When developing and debugging interfaces, it is common to switch between different environments. Frequently changing the interface request URL can significantly increase debugging time.
Therefore, you can use environment management to quickly switch the pre-URL of the interface to achieve the purpose of debugging the same interface in different environments.
You can manage different environment URLs for your project through the environment management feature in the upper right corner. By simply selecting from a dropdown menu, you can quickly switch the pre-URL of the interface for faster debugging.
How to Create a New Environment
Note: When creating a new environment, the prefix portion of the interface request URL is typically extracted and used as the environment's URL.
Private and Public Environments
When creating a new environment, you can choose whether to set the environment as public or private.
Public: All project members can view it. Public environments are typically used for shared resources.
Private: Only visible to you. Typically, the local environment for the developer is set to private. If the environment involves sensitive information variables, it is recommended to manage them under the private environment.
Note: Public environments cannot be reverted to private, while private environments can be changed to public.
Management of Environment Variables
The same parameter key can have different values across environments. By managing these variables using environment variables, you can quickly switch between environments for faster debugging.
Adding Environment Variables
There are two ways to add variables:
- Manually add variables in the pop-up window and save them. 提示
Once environment variables are set, simply switch environments, and the request parameters will automatically update with the corresponding variable values.
2. Add through post-execution operations (for details on post-execution operations, please refer to the specific introduction in the relevant documentation).
pm.environment.set("account", "John"); // Set an environment variable, the value of account is set to John.
Using Environment Variables
In various places of the request parameters, you can refer to it through {{variable name}}:
You can also do it in Raw mode.
After setting the environment variables, simply switch the environment. When a request is sent, these parameters will be automatically replaced by the corresponding environment variable values.
Viewing Environment Variables
Usage of Multiple Host Services (Pre-URL)
Generally, using multiple services is not recommended. However, in cases where interfaces in the same environment are deployed on different services—resulting in varying pre-URLs—multiple host services can be configured.
Adding Services
In the environment management, add services and set the pre-URL address for different services in each environment.
Support for deleting or modifying service names.
How to Use
For better organization, it is recommended to first classify interfaces deployed under the same service into directories. For example, interfaces related to users can be placed in the [User] directory. Then, assign the service to the [User] directory so that all interfaces within the directory consistently use the pre-URL of that service.
First, classify and manage the interfaces by folder
Then select the folder, select Edit, and specify the host service for the folder
After specifying the service, click save to take effect.
Once the service is assigned, the pre-URL for the interfaces in the directory will be set to the specified service URL. Additionally, when switching environments, all URLs will point to the [User Service]."