When making API requests, it is often necessary to switch between development, testing, and production environments. Apidog makes it convenient to send requests to different environments - you simply need to click and select the desired environment at the top right corner of the interface.An Apidog environment consists of two core elements. The first is the base URL
, used to maintain the target of request delivery. The second element comprises one or more groups of variables
that can be referenced in requests or scripts. When switching between environments, both the base URL and environment variables will use the values defined in the current environment.Create an environment#
1
Click on the "Environment Management" button ≡
in the top right corner of the interface.
2
Click on the last item in the left-side list labeled New Environment
.
3
Enter a name for your new environment. Add the base URL and variables.
5
To use the new environment, select it from the environment selector at the top right of the interface. This makes it the active environment and sets all variables to the values specified in the environment.
Environments in Apidog are distinct from those in Postman, where there is a tendency to associate each Base URL with a separate environment. This blurs the lines between environments and base URLs.In contrast, Apidog's environments directly reflect real environments like development, testing, and production, rather than treating each base URL as one single environment.For example, within a testing environment, there may be various services such as user service and order service all contained within the same testing environment. It is important that these services are not divided into separate user and order environments.
Base URLs#
The base URL is the primary feature in an Apidog environment. In Apidog, an endpoint starts with a forward slash (/
) and does not include the base URL; when sending an endpoint request, it is necessary to specify the destination base URL. This underlines the importance of the base URL feature in the environment — selecting a right environment is a prerequisite for sending an endpoint request.A standardized base URL format begins with the protocol and without trailing slash (/), likeEach base URL corresponds to a specific Module. In most cases, an endpoint will use the Base URL of its module to send requests.For instance, if the base URL of the default module for the production environment is http://abc.com/v1
and your endpoint path is /pet
, then when you send a request in the production environment, the actual request sent would be:If the endpoint path begins withhttp://
orhttps://
, the base URL will not be appended to the request. Nonetheless, this practice is generally discouraged.
In Apidog, there is a special environment variable called BASE_URL, which stores the base URL for the "Default Server" of the current environment. It is generally discouraged to use this variable.For custom scripts, it is recommended to use pm.request.getBaseUrl()
to fetch the base URL for the present endpoint. Avoid using pm.environment.get('BASE_URL')
, as it may not correctly capture the base URL for the current endpoint if the endpoint does not employ the "Default Server."If the user manually creates an environment variable labeled BASE_URL
, it will supersede the system's predefinedBASE_URL
.Scripts are unable to modify the base URL. The command pm.environment.set('BASE_URL', 'My_url')
within a script will establish a genuine environment variable calledBASE_URL
instead of altering the base URL itself.
Using Multiple Base URLs with Modules#
If your project’s endpoints need to connect to multiple base URLs, the best way to manage them is by using multiple modules in Apidog.User-related endpoints requests point to https://user.example.com
Order-related endpoints requests point to https://order.example.com
Product-related endpoints requests point to https://product.example.com
Here’s how you can set it up:1
At the top of the API folder tree, add multiple modules successfully.
2
In
Environment Management, you’ll now see fields to set the
Base URL for each module. Enter the actual URLs for each and click
Save.
3
In a module’s
root folder, you can choose which
Base URL the module’s endpoints should use:
Default Settings: Uses the first Base URL listed for that module. This is the standard and recommended setting.
Manually Specify: You can select another Base URL manually from the same module if needed. This is useful if a single module needs to interact with multiple services — but this approach is not recommended anymore. It’s better to split services into separate modules instead.
4
In the
subfolder or individual
endpoint page of a module, you can also specify which Base URL to use:
Inherit from Parents: Follows the setting of the parent folder (default behavior).
Manually Specify: You can select a different Base URL from within the same module. This is useful if a single module needs to interact with multiple services (base URL) — but this approach is not recommended anymore. For microservices, we advise using separate modules.
5
Once the correct environment is selected, just click Send. Whether you’re sending an individual endpoint request or running automated tests, Apidog will determine the proper Base URL based on the module and environment settings.
6
Each different environment includes all modules of the project, and the Base URLs for these modules need to be set individually in each environment.
This is important because most teams have different Base URLs for development, testing, and production. When you switch environments in the upper-right corner, Apidog will automatically route all endpoint requests to the correct service based on the environment's Base URL settings — making your workflow more efficient.There is a default module when creating a new project. If, in rare cases, a valid Base URL isn’t found for a module, the system will fall back to the Base URL of this default module.
Add environment variables#
When you add a variable to an environment, you can specify the Initial value (shared) and the Current value (local) for the variable.Switch between environments#
Apidog shows the current environment in the environment selector at the top right of the workbench. Whenever you make a request or execute a script, Apidog will use the current values for all variables in the selected environment.To switch to a different environment, simply choose it from the environment selector.In Apidog, endpoints and requests are two distinct concepts. An endpoint represents the API specification and does not include the base URL, whereas a request is the concrete API request, which includes the base URL. Therefore, the services defined in an Apidog environment only apply to endpoints, not to requests.When using the requests functionality, you can leverage the environment variables in a similar way to Postman, by using the {{Base_url}} syntax.
Environment Migration#
In Apidog, the Initial value of variables is synchronized within the team, while the Current value is only stored locally. This means that when you use Apidog on another computer, you won't have access to the previously used Current values.Therefore, Apidog provides the functionality to migrate environments. You can export the services and variables in environments as a JSON file and then import it on another computer. Here are the steps:1
In the environment management, hover over the
...
next to the Environments list, click Export to obtain a JSON file.
2
On another computer, open environment management, hover over the ...
next to the Environments list, and click Import. Select the JSON file to import.
3
You can also import environments exported from Postman.
Visibility Scope of Environments#
Sometimes, you may need to create variables for personal use only and prefer they are not visible to others. In such cases, you can create a Private Environment.In the top right corner of the environment, you can set the visibility scope of the environment. By default, it is shared, while you can make environments you create visible only to yourself. However, you cannot change the visibility of environments created by others.Private Environments share the same Service list as other environments. Adding or removing services in a Private Environment will affect all environments simultaneously.