Creating an Environment and Environment Variable¶
Scenario¶
An API can be called in different environments, such as production, testing, and development environments. RELEASE is the default environment provided by APIG. You can define environment variables to allow an API to be called in different environments.
Environment variables are manageable and specific to environments. You can create variables in different environments to call different backend services using the same API.
For variables you define during API creation, you must create corresponding variables and values. For example, variable Path is defined for an API, and two variables with the same name are created and assigned values /Stage/test and /Stage/AA in environments 1 and 2, respectively. If the API is published and called in environment 1, the path /Stage/test is used. If the API is published and called in environment 2, the path /Stage/AA is used.
Note
You can create a maximum of 50 variables for an API group in each environment.
Prerequisites¶
You have created an API group.
Creating an Environment¶
Log in to the management console.
In the navigation pane, choose Dedicated Gateways. Then click Access Console in the upper right corner of a dedicated gateway.
In the navigation pane, choose API Publishing > Environments.
Click Create Environment, and set the parameters listed in Table 1.
¶ Parameter
Description
Name
Environment name.
Description
Description of the environment.
Click OK.
After the environment is created, it is displayed in the environment list.
Accessing an Environment¶
You can call an API in the RELEASE environment by using a RESTful API. To access the API in other environments, add the X-Stage header to the request to specify an environment name. For example, add X-Stage:DEVELOP to the request header to access an API in the DEVELOP environment.
Note
APIG does not support API debugging using environment variables.
Creating an Environment Variable¶
Log in to the management console.
In the navigation pane, choose Dedicated Gateways. Then click Access Console in the upper right corner of a dedicated gateway.
In the navigation pane, choose API Publishing > API Groups.
Create a variable. You can use one of the following methods:
Click the name of the target API group, and click the Variables tab on the displayed API group details page.
In the Operation column of the target API group, choose More > Manage Variable.
Select an environment from the Environment drop-down list, and click Create Variable.
Set the parameters listed in Table 2.
¶ Parameter
Description
Name
Name of the variable you want to create. Ensure that the name is the same as the name of the variable defined for the API.
Value
The path to be used in the selected environment.
Click OK.
Note
If a variable is not needed, click Delete in the row containing the variable to delete it.
Environment variable names and values will be displayed in plain text in API requests. Do not include sensitive information in the variable names and values.
Follow-Up Operations¶
After creating an environment and variable, publish APIs in the environment so that they can be called by API callers.