Skip to main content

Environment Variable Concept

Environment variables are used to securely store sensitive information (passwords, API keys, certificates) or configuration values. In Apinizer, 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

Encryption Support

Sensitive information can be stored encrypted

Level-Based

Can be defined at environment or project level

Security

Encrypted variables are stored securely

Reusability

Can be used in multiple API Proxies or Task Flows

Environment Variable Resolution Flow

The following diagram shows how environment variables are resolved at runtime and how values are retrieved according to the environment:

Environment Variable Types

Encrypted

Used for sensitive informationSensitive information such as passwords, API keys, certificates, and tokens are stored encrypted.
Important: Encrypted variables are encrypted irreversibly. Values are only decrypted during use.

Unencrypted

Used for configuration valuesURLs, port numbers, flags, and other configuration values are stored unencrypted.
  • Passwords: Database passwords, API keys
  • Certificates: SSL/TLS certificates
  • Tokens: OAuth tokens, JWT secrets
  • Other Sensitive Information: All values requiring security
  • URLs: Backend API URLs
  • Port Numbers: Port values
  • Flags: Boolean values
  • Other Configurations: General configuration values

Environment Variable Levels

Environment-Level

Valid in a specific environmentCan be used by all API Proxies and Task Flows in that environment. Has higher priority than project-level variables.

Project-Level

Valid in a specific projectCan be used by all API Proxies and Task Flows in that project. Has lower priority than environment-level variables.
  • Environment-based backend URLs
  • Environment-based API keys
  • Environment-based configuration values
  • Environment-based database connection information
  • Project-based configuration values
  • Project-based API keys
  • Project-based general settings
  • Project-based common values

Environment Variable Priority Order

Variable resolution order (from highest to lowest):

1. Environment-Level Encrypted

Highest priorityEnvironment-level encrypted variables.

2. Environment-Level Unencrypted

Second priorityEnvironment-level unencrypted variables.

3. Project-Level Encrypted

Third priorityProject-level encrypted variables.

4. Project-Level Unencrypted

Lowest priorityProject-level unencrypted variables.
Note: If a variable with the same name is defined at both environment and project levels, the environment-level variable is used.

Working Logic

1. Definition

Environment variables are defined at the project level
  • Global: Same value in all environments
  • Environment-Specific: Different value for each environment

2. Usage

Used in configuration fields in ${variableName} format
  • Backend address: ${BACKEND_URL}
  • Database: jdbc:mysql://${DB_HOST}:${DB_PORT}/${DB_NAME}
  • API key: ${API_KEY}

3. Runtime Resolution

Automatically resolved when API Proxy runs
  • Variable expressions are detected
  • Environment value is retrieved
  • Secrets are decrypted
  • Replaced with actual value
Configuration:
  • Development: BACKEND_URL = dev-api.example.com
  • Production: BACKEND_URL = api.example.com
  • In configuration: ${BACKEND_URL}
Runtime Results:
  • In Development environment: dev-api.example.com
  • In Production environment: api.example.com

Environment Variable Usage Format

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

Format Structure

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

Format Rules

Start Character

Must start with ${

End Character

Must end with }

Variable Name

Variable name in the middle (without spaces)

Case Sensitivity

Variable name is case-sensitive

Environment Variable Usage Locations

Environment variables can be used in various configuration fields in the Apinizer platform. Environment Variable Selection Dialog is only available in certain fields.

API Proxy - Routing

Upstream Routing addressesLocation: API Proxy > Upstream/Routing Tab > Define Address(es)Used for environment-based routing in Backend API addresses.

Database Connection

Database connection configurationLocation: Administration > Connection Management > Database Connection PoolEnvironment-based management in JDBC URL, Username, Password fields.

LDAP Connection

LDAP connection configurationLocation: Administration > Connection Management > LDAP Connection PoolEnvironment-based management in LDAP URL, Bind DN, Bind Password fields.
FeatureDescription
LocationAPI Proxy > Upstream/Routing Tab > Define Address(es)
FieldBackend API address input field
UsageEnvironment-based routing in Backend API addresses
AccessBy clicking the list icon button on the right side of the address input field
Usage Scenario: To use different backend addresses in different environments
FeatureDescription
LocationAdministration > Connection Management > Connection Pool Def DB
FieldsJDBC URL, Username, Password
UsageEnvironment-based management in database connection information
Dialog AccessBy clicking the list icon button on the right side of each field
Secret UsagePassword field must be marked as secret
Usage Scenario: To use different database connection information in different environments
FeatureDescription
LocationAdministration > Connection Management > Connection Pool Def LDAP
FieldsLDAP URL, Bind DN, Bind Password
UsageEnvironment-based management in LDAP connection information
Dialog AccessBy clicking the list icon button on the right side of each field
Secret UsageBind Password must be marked as secret
Usage Scenario: To use different LDAP connection information in different environments

Usage Scenarios and Examples

Problem: Different backend API addresses are used in different environments.Solution:Creating 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
Usage in Routing:
  • Address: ${BACKEND_API_URL}
Result:
  • In Development environment, requests go to https://dev-api.example.com
  • In Test environment, requests go to https://test-api.example.com
  • In Production environment, requests go to https://api.example.com
Problem: Different databases are used in each environment.Solution: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)
Usage in Connector:
  • Connection String: jdbc:mysql://${DB_HOST}:${DB_PORT}/${DB_NAME}
  • Username: ${DB_USER}
  • Password: ${DB_PASSWORD}
Result:
  • Development: jdbc:mysql://dev-db.example.com:3306/dev_db
  • Production: jdbc:mysql://prod-db.example.com:3306/prod_db
Problem: Different API keys are used for external services.Solution:Environment Variable:
  • Key Name: EXTERNAL_SERVICE_API_KEY
  • Type: Environment-Specific
  • Development: dev-key-abc123 (Secret)
  • Production: prod-key-xyz789 (Secret)
Usage in Policy:
  • Header Name: X-API-Key
  • Header Value: ${EXTERNAL_SERVICE_API_KEY}
Result:
  • Development: X-API-Key: dev-key-abc123
  • Production: X-API-Key: prod-key-xyz789

Environment Variable Creation

Environment variable creation steps:
  • Go to Environment Variables page
  • Click the “Create” button in the upper right corner
  • Environment Variable editing window opens
  • Key Name (Variable Name):
    • Required field
    • Must be unique within the project
    • Name check is performed automatically
    • Valid name: Green checkmark
    • Existing name: Red warning sign
  • Description:
    • Optional field
    • Describes what the variable is used for
  • Environment-Specific:
    • Different values can be defined for each environment
    • Selected when creating new record
    • Cannot be changed after record is created
  • Global (All Environments):
    • Same value used in all environments
    • Selected when creating new record
    • Cannot be changed after record is created
Important: Type selection can only be done when creating a new record. The type of existing records cannot be changed.
For Environment-Specific Variables:
  • Adding Environment: Click “Add Environment” button to add new environment
  • Environment Selection: Select an environment for each value
    • Existing environments are selected from the list
    • Custom environment name can be entered with “Custom…” option
  • Entering Value: Enter value for each environment
  • Secret Setting: Check “Secret” checkbox for sensitive information
    • Secret values are masked after saving (***********)
    • Secret values are stored encrypted
    • If value is not changed during update, existing value is preserved
For Global Variables:
  • Global Value: Enter a single value (valid for all environments)
  • Secret Setting: Check “Secret” checkbox for sensitive information
  • Form Validation: All required fields must be filled and name must be valid
  • Click “Save and Deploy” button
  • Confirmation Dialog:
    • You are asked to enter the variable name again (for security)
    • Affected components are listed:
      • API Proxy Routing settings
      • Policy Configuration settings
      • Connector settings
      • Other configuration settings
  • Deployment Result:
    • Automatically deployed to all running environments
    • Deployment results are shown
Important: Values marked as Secret cannot be viewed again after saving.

Environment Variable Editing

Opening the Edit Modal

The edit modal can be opened in the following ways:
MethodDescription
Clicking from ListClick on the environment variable name
Selecting from MenuSelect “Edit” from the menu at the end of the row

Differences in Edit Modal

FeatureNew RecordEdit
Modal Title”Add Environment Variable""Edit Environment Variable”
Type SelectionActive (can be changed)Inactive (cannot be changed)
Secret ValuesVisible normallyVisible masked (***********)
Secret CheckboxActiveInactive for saved secrets

Best Practices

  • Always store sensitive information encrypted
  • Use encrypted for passwords, API keys, certificates
  • Regularly change passwords
  • Name variables consistently
  • Properly separate environment and project level variables
  • Create documentation
  • Clean up unused variables
  • Regularly review variable usage
  • Perform version control

Next Steps