Skip to main content

Environment Management

A project will be in different environments at different stages, such as development, test, and production environments. Different environments usually have different base URLs, API parameter values, etc. It is very tedious to update the base URL and parameters frequently when the environment changes. with Apidog's environment management function, you only need to set different base URLs and parameters for different environments, and switch the environments when testing.

Environment Setup

Entring Environment Management

The entrance to the environment management section is in the page's upper right corner. The Environment Management portal can be accessed in one of two ways:

Environment Management Page

You can create or delete an environment on the left side and edit an environment on the right side.

Features

  1. Base URL: Automatically gets added to the API path to form the URL of the actual request. For example, if the base URL is https://www.api.com and the path entry is /pets/123, the URL of the actual request is https://www.api.com/pets/123.
  2. Additional Parameters: Automatically gets added to all the API of a given environment. The value of additional parameters can refer to environment variables/global or variables/local .
TIP
  1. We suggest not adding / at the end of the base URL and adding the / at the beginning of the entry path when designing the API.
  2. If the API path starts with http:// or https://, the base URL will not be added to the actual request. However, this is usually not recommended.
TIP
  • The system includes a special environment variable named BASE_URL, which holds the base URL for the "Default Server" of the current environment. It is generally not recommended to use this.
  • For custom scripts, it is advised to use pm.request.getBaseUrl() to retrieve the base URL for the current API. Do not use pm.environment.get('BASE_URL'), as if the API does not use the "Default Server", the BASE_URL retrieved will not be the base URL for the current API.
  • If the user manually adds an environment variable named BASE_URL, it will override the system's built-in BASE_URL.
  • Scripts cannot modify the base URL. The script command pm.environment.set('BASE_URL', 'xxx') will create an actual environment variable named BASE_URL instead of modifying the "base URL."

Quickly Switching Environments

You can quickly switch to the environment you need in the upper right corner of the page.

Services (Base URL)

Please do not add multiple services under normal circumstances.

They need to be added only when multiple API uses different base URLs, under the same environment.In this scenario, each Service should have a different base URL, and different API or groups should choose different services.

The Difference Between Service and Environment

Usage Scenario

Environment

Development Environment
Debugging Environment
Pre-release Environment
Production Environment

Service

User Service (user.xxx.com): Log in and other API
Transaction Service(trade.xxx.com): Transaction-related Service
Streaming Service (live.xxx.com): Streaming-related Service

Service Setup

You can enter the base URL on the Environment Management page.

Using Service

  1. In the group settings, you can set different services in the current environment (recommended).

  2. In the API Document - Modify Document, you can set different services in the current environment.