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.
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
- Access the shared gateway console.
- In the navigation pane, choose API Publishing > Environments.
- Click Create Environment, and set the parameters listed in Table 1.
Figure 2 Creating an 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.
APIG does not support API debugging using environment variables.
Creating an Environment Variable
- 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.
Figure 3 Creating an environment variable
- Click OK.
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.
Creating an Environment and Environment Variable by Calling an API
You can also create an environment and environment variable by calling an API provided by APIG. For details, see the following references:
FAQ About Environment Variables
Can I Invoke Different Backend Services by Publishing an API in Different Environments?
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot