Help Center/ API Gateway/ User Guide/ Opening APIs/ (Optional) Configuring the Environment and Environment Variables
Updated on 2024-11-27 GMT+08:00

(Optional) Configuring the Environment and Environment Variables

An environment refers to the usage scope of an API. An API can be called only after it is published in an environment. APIs can be published in different customized environments, such as the development environment and test environment. RELEASE is the default and formal publishing environment of the system.

Environment variables are specific to environments. If environment variables are defined in backend information of an API, you need to add the variables to the environment. You can create variables in different environments to call different backend services using the same API.

Example: an API whose variable Path is defined in the backend request path. If variable Path is configured for environment 1 and is assigned value /Stage/test, use the backend request path /Stage/test to call this API in this environment. If variable Path is configured for environment 2 and is assigned value /Stage/AA, use the backend request path /Stage/AA to call this API in this environment.

Figure 1 Use of environment variables

Creating an Environment

  1. Go to the APIG console.
  2. Select a dedicated gateway at the top of the navigation pane.
  1. In the navigation pane, choose API Management > API Policies.
  2. Click the Environments tab.
  1. Click Create Environment and set the environment information.

    Table 1 Environment information

    Parameter

    Description

    Name

    Environment name.

    Description

    Description of the environment.

  2. Click OK.

    After the environment is created, it is displayed in the environment list.

    When a user needs to call an open API, the API in the RELEASE environment is called by default. To access an API in another environment, add the X-Stage parameter to the header of the API request, where the parameter is the environment name. For example, to access an API in the Develop environment, add X-Stage: Develop to the header of the API request.

Creating an Environment Variable

  1. Go to the APIG console.
  1. Select a dedicated gateway at the top of the navigation pane.
  1. Choose API Management > API Groups.
  2. Click a group name.
  3. Click the Group Information tab.
  4. In the Environment Variables area, select an environment. If no environment is available, click Create Environment to create one.
  5. Click Add Environment Variable and enter the variable information.

    • 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.
    • APIG does not support API debugging with environment variables.
    Table 2 Adding an environment variable

    Parameter

    Description

    Name

    Variable name. 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.

  6. Click OK.

Follow-Up Operations

You can publish an API in the environment for calling.