Skip to main content

Environment

tip

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.

image.png

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.

image.png

image.png

image.png

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.

image.png

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.

image.png

Adding Environment Variables

There are two ways to add variables:

  1. Manually add variables in the pop-up window and save them.
    tip

    Once environment variables are set, simply switch environments, and the request parameters will automatically update with the corresponding variable values.

image.png 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.

image.png

Using Environment Variables

In various places of the request parameters, you can refer to it through {{variable name}}:

image.png

You can also do it in Raw mode.

image.png

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.

image.png

Viewing Environment Variables

image.png

Usage of Multiple Host Services (Pre-URL)

tip

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.

image.png

Adding Services

In the environment management, add services and set the pre-URL address for different services in each environment.

image.png Support for deleting or modifying service names.

image.png

How to Use

tip

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

image.png

Then select the folder, select Edit, and specify the host service for the folder

image.png

image.png

After specifying the service, click save to take effect.

image.png

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]."

image.png