Environment Variables
Environment variables are variables with unique values within a specific environment. They are used as extra configurations for each environment, allowing the customization of requests to easily switch between different contexts. Creating them is not mandatory, but their use facilitates the process of designing and managing APIs.
The API Manager allows creating environment variables to be used in various parts of our platform:
-
In the Target or Timeout of the API Destination;
-
When enabling a Connector; or
-
In various Interceptors, as shown in the table below.
List of interceptors that allow the use of environment variables:
Time allowed |
XML Threat protection |
Service mashup |
Query param |
Imagine several APIs deployed to an environment share the same target destination and, at some point, that destination changes. Without environment variables, it would be necessary to change the target destination in each API. However, if the destination had been set as an environment variable, just change the value of that variable in the specific environment, and all APIs will be automatically updated. |
Registering environment variables
To register environment variables, you must create a variables map or import an existing one from another environment.
To add a map:
-
Click the ADD MAP button;
-
In the screen that opens, define the name for the map.
Now you can create environment variables as key-value pairs, both of type string.
The Type field allows you to change the variable type to one of the options below:
-
DEFAULT: the default type for all variables. Doesn’t change their behavior.
-
SECURED: encrypted value, decrypted only by a Connector’s flow, adding more security when storing its credentials since the value isn’t retrievable in any other way.
You can also add a certificate corresponding to the communication between the gateway and the backend. When the environment variable is used, it will be applied:
-
Click the icon;
-
Select the registered certificate on the Certificates screen;
To import a map from another environment:
-
Click the IMPORT MAP button;
-
When you start typing the environment name, the system will load the necessary information;
-
After selecting the map, click IMPORT MAP.
The environment variables will be loaded. You will be able to:
-
view them by clicking the icon to extend the tab next to the map’s name;
-
edit them by clicking the icon;
-
delete them by clicking the icon;
-
add new variables to a map by clicking the icon and then the + button.
On this same tab, you can edit the map’s name and description, or delete it.
Managing environment variables
When you create variables in an environment, they are associated with the environment as a whole, not with a specific API. Therefore, it is important to follow good management and organization practices. We recommend using a clear and consistent naming pattern for all variables. This makes it easier to identify and use them correctly.
Usage example
Consider two environment variables: one named destination
, with a valid address, and one named rateLimit
, with value 2
.
The environment variable $destination
can be used as an API endpoint.
When a request is made, the gateway will direct the call to the configured address.
To set this up, just reference the environment variable as the API’s Target Destination, as shown in the image below:
The environment variable $rateLimit
can be used in the interceptor of the same name to set the call limit, replacing the configured value (in this case, 2
).
|
Share your suggestions with us!
Click here and then [+ Submit idea]