Environment Variables is a feature in the Apinizer API Management Platform that allows you to centrally manage configuration information that requires different values in different environments (Development, Test, Production). This feature enables the same API Proxy configuration to dynamically use different values such as backend addresses, database connection information, and API keys in different environments.

How It Works

1. Definition Phase

Environment variables are defined at the project level and can be of two types:

  • Global (All Environments): Uses the same value in all environments
  • Environment-Specific: Different values can be defined for each environment

2. Usage Phase

Environment variables are used in configuration fields in the format ${variableName}:

  • Example 1: ${BACKEND_URL} for the backend address
  • Example 2: jdbc:mysql://${DB_HOST}:${DB_PORT}/${DB_NAME} for the database connection string
  • Example 3: For the API key, use ${API_KEY}

3. Runtime Resolution

When the API Proxy is running (runtime):

  • Expressions in the format ${variableName} in the configuration are detected
  • The variable value for the relevant environment is retrieved
  • Secret values are automatically decrypted
  • The variable name is replaced with the actual value
  • The process continues with the actual value

Example Scenario:

Creating an Environment Variable (Create)

The visual containing the steps for creating an environment variable is provided below:

The configurations for creating environment variables are explained step by step in the table below:

Step Function

Step 1: Adding a New Environment Variable

  1. Go to the Environment Variables page
  2. Click the “Create” button in the upper right corner
  3. The Environment Variable editing window opens

Step 2: Enter Basic Information

Key Name (Variable Name):

  1. Required field
  2. Must be unique within the project
  3. Name validation is performed automatically
  4. Valid name: Green check mark
  5. Current name: Red warning mark

Description:

  1. Optional field
  2. Explains what the variable is used for

Step 3: Selecting the Type

Environment-Specific:

  • Different values can be defined for each environment
  • Selected when creating a new record
  • Cannot be changed after the record is created

Global (All Environments):

  • The same value is used in all environments
  • Selected when creating a new record
  • Cannot be changed after the record is created

The type selection can only be made when creating a new record. The type of existing records cannot be changed.

Step 4: Value Definition

Environment-Specific Variables:

  1. Add Environment: Click the “Add Environment” button to add a new environment
  2. Environment Selection: Select an environment for each value
    1. Existing environments are selected from the list
    2. A custom environment name can be entered using the “Custom...” option
  3. Value Entry: Enter a value for each environment
  4. Secret Setting: Check the “Secret” checkbox for sensitive information
    1. Secret values are masked (************) after being saved
    2. Secret values are stored encrypted
    3. If the value is not changed during update, the existing value is preserved

For Global Variables:

  1. Global Value: Enter a single value (applies to all environments)
  2. Secret Configuration: Check the “Secret” checkbox for sensitive information


Step 5: Saving and Deployment

  1. Form Kontrolü: Tüm zorunlu alanlar doldurulmalı ve isim geçerli olmalı
  2. "Kaydet ve Deploy" butonuna tıklayın
  3. Onay Dialog'u:
    • Değişken adını tekrar girmeniz istenir (güvenlik için)
    • Etkilenecek bileşenler listelenir:
      • API Proxy Routing ayarları
      • Policy Configuration ayarları
      • Connector ayarları
      • Diğer yapılandırma ayarları
  4. Deployment Sonucu:
    • Tüm çalışan ortamlara (Environments) otomatik olarak deploy edilir
    • Deployment sonuçları gösterilir


  1. Form Validation: All required fields must be filled in and the name must be valid.
  2. Click the “Save and Deploy” button.
  3. Confirmation Dialog:
    1. You will be asked to re-enter the variable name (for security)
    2. Affected components are listed:
      1. API Proxy Routing settings
      2. Policy Configuration settings
      3. Connector settings
      4. Other configuration settings
  4. Deployment Result:
    1. Automatically deployed to all running environments
    2. Deployment results are displayed

Once values marked as secret are saved, they cannot be viewed again.

Environment Variable Editing (Edit)

Opening the Editing Modal

The editing modal can be opened in the following ways:

MethodDescription
Click from the ListClick on the environment variable name
Select from the MenuSelect “Edit” from the menu at the end of the line

Differences in the Modal Settings

FeatureNew EntryEdit
Modal Header“Add Environment Variable”"Edit Environment Variable"
Type SelectionActive (editable)Inactive (non-editable)
Secret ValuesVisible normallyVisible masked (************)
Secret CheckboxActivePassive for saved secrets

Use of Environment Variables

Environment variables can be used in various configuration areas within the Apinizer API Manager platform. This section details how environment variables can be used, in which configurations they can be used, and provides practical examples.

Usage Format

Environment variables are referenced using a special format in configuration files.

 Format Structure

FormatDescriptionExample
${variableName}Basic usage format${BACKEND_URL}
text${variableName}Merge with texthttps://${API_HOST}
${variableName}textMerge with text${API_PORT}/api
text${variable1}text${variable2}Multiple variablesjdbc:mysql://${DB_HOST}:${DB_PORT}/${DB_NAME}

Format Rules

RuleDescription
Start CharacterMust begin with ${
End CharacterMust end with }
Variable NameThe variable name appears in the middle (without spaces)
Uppercase/LowercaseVariable names are case-sensitive
Special CharactersThe variable name can contain periods (.) and underscores (_)

Usage Locations

Environment variables can be used in various configuration areas on the Apinizer platform. However, the Environment Variable Selection Dialog is only available in certain areas.

1. API Proxy - Routing

Usage Area: Upstream Routing addresses

FeatureDescription
LocationAPI Proxy > Upstream/Routing Tab > Define Address(es)
FieldBackend API address input field
UsageEnvironment-based routing for backend API addresses
AccessBy clicking the list icon button to the right of the address input field

2. Database Connection

Usage: Database connection configuration

FeatureDescription
LocationAdministration > Connection Management > Connection Pool Def DB
FieldsJDBC URL, Username, Password
UsageEnvironment-based management of database connection information
Dialog AccessBy clicking the list icon button to the right of each field
Secret Usage  The Password field must be marked as secret 

Usage Scenario: To use different database connection information in different environments

3. LDAP Connection

Usage: LDAP connection configuration

PropertyDescription
LocationAdministration > Connection Management > Connection Pool Def LDAP
FieldsLDAP URL, Bind DN, Bind Password
Usage Environment-based management of LDAP connection information
Dialog AccessBy clicking the list icon button to the right of each field
Secret UsageBind Password must be marked as secret

Senaryo

ProblemÇözüm

Backend API Address Management

Different backend API addresses are used in different environments.
  1. Creating an Environment Variable:

    Key Name: BACKEND_API_URL
    Type: Environment-Specific
    Development: https://dev-api.example.com
    Test: https://test-api.example.com
    Production: https://api.example.com
    
  2. Usage in Routing:

    Address: ${BACKEND_API_URL}
    
  3. Result

Database Connection Management

Different databases are used in each environment.
  1. Environment Variables

    DB_HOST: Development=dev-db.example.com, Production=prod-db.example.com
    DB_PORT: Global=3306
    DB_NAME: Development=dev_db, Production=prod_db
    DB_USER: Development=dev_user, Production=prod_user
    DB_PASSWORD: Development=dev_pass, Production=prod_pass (Secret)
    
  2. Use in Connector:

    Connection String: jdbc:mysql://${DB_HOST}:${DB_PORT}/${DB_NAME}
    Username: ${DB_USER}
    Password: ${DB_PASSWORD}
    
  3. Result:

API Key Management

Different API keys are used for external services.
  1. Environment Variable:

    Key Name: EXTERNAL_SERVICE_API_KEY
    Type: Environment-Specific
    Development: dev-key-abc123 (Secret)
    Production: prod-key-xyz789 (Secret)
    
  2. Usage in Policy

    Header Name: X-API-Key
    Header Value: ${EXTERNAL_SERVICE_API_KEY}
    
  3. Result:

    • Development: X-API-Key: dev-key-abc123
    • Production: X-API-Key: prod-key-xyz789