⚡
Serverless API Gateway Documentation
Creator
⚡
Serverless API Gateway Documentation
  • Serverless API Gateway
  • Getting Started
    • Introduction
    • Cost
  • Configuration
    • Overview
    • Servers
    • Service Binding
    • Paths
      • Add and Remove Prefix
    • Authorizer
    • CORS
    • Variable Mapping
      • Priority Variables
    • Integrations
      • Auth0
  • Deployment
    • Wrangler
    • GitHub Actions
  • Glossary
    • A
      • API (Application Programming Interface)
      • API Endpoint
      • API Gateway
      • API Key
      • API Rate Limiting
      • Asynchronous Operation
      • Authentication
      • Authorization
    • B
      • Backend as a Service (BaaS)
      • Blueprint
    • C
      • Cache
      • CDN (Content Delivery Network)
      • CI/CD (Continuous Integration/Continuous Deployment)
      • Client
      • Client-Side Rendering (CSR)
      • Cloud Service Provider (CSP)
      • Cluster
      • Container
      • Continuous Delivery
      • Continuous Integration
      • Cron Job
    • D
      • Data Lake
      • Data Warehousing
      • Database
      • Deployment
      • DevOps
      • Distributed System
      • DNS (Domain Name System)
      • Docker
      • Domain
    • E
      • Edge Computing
      • Elasticity
      • Endpoint Security
      • Environment Variables
      • Event-Driven Architecture
    • F
      • Fault Tolerance
      • Firewall
      • Function as a Service (FaaS)
    • G
      • Git
      • GraphQL
    • H
      • Hashing
      • High Availability (HA)
      • HTTP (Hypertext Transfer Protocol)
      • HTTPS (Hypertext Transfer Protocol Secure)
    • I
      • Infrastructure as a Service (IaaS)
    • J
      • JSON (JavaScript Object Notation)
    • K
      • Kubernetes
    • L
      • Latency
      • Load Balancer
      • Logging
    • M
      • Microservices
      • Middleware
      • Migration
      • Mocking
      • Monolithic Architecture
      • Multi-Cloud
    • N
      • Network Protocol
    • O
      • OAuth
      • Object Storage
      • Orchestration
    • P
      • PaaS (Platform as a Service)
      • Payload
      • Performance Testing
      • Plugin
      • Private Cloud
      • Public Cloud
      • Pull Request
    • Q
      • Query Language
      • Query Parameters
      • Queue
    • R
      • Rate Limiting
      • Real-Time Processing
      • Redundancy
      • Refactoring
      • Regression Testing
      • Repository
      • REST (Representational State Transfer)
      • Rollback
    • S
      • SaaS (Software as a Service)
      • Scalability
      • Schema
      • SDK (Software Development Kit)
      • Service Mesh
      • Session
      • SLA (Service Level Agreement)
      • SOAP (Simple Object Access Protocol)
      • State
      • Stateless
      • Static Site Generator
      • Storage
      • Stress Testing
      • Swagger (OpenAPI)
Powered by GitBook
On this page
Edit on GitHub
  1. Configuration
  2. Variable Mapping

Priority Variables

When resolving values for mappings in the Serverless API Gateway, it's crucial to understand the priority order between local (config) variables and global variables.

Variable Resolution Hierarchy

The Serverless API Gateway uses a specific order of precedence when resolving variables to ensure that the most relevant and specific settings are applied to each request. This order is as follows:

  1. Local (Config) Variables: These are variables defined within the scope of a specific path in the API gateway configuration. They are intended to be specific to the individual endpoint or set of endpoints defined by that path configuration. When a variable is referenced in a mapping, the system first checks if it exists as a local variable for that path.

  2. Global Variables: Global variables are defined at a higher level in the API gateway configuration and are intended to provide default values that apply across multiple paths or the entire API. If a variable referenced in a mapping is not found among the local variables, the system then checks the global variables for a match.

Why Local Variables Take Precedence

The prioritization of local variables over global ones is designed to provide flexibility and specificity in API configuration. This approach allows developers to:

  • Override Global Settings: Define specific behaviors or values for certain endpoints without changing the global configuration. This is useful for exceptions or special cases within your API.

  • Maintain Configurational Flexibility: Easily adjust the behavior of individual endpoints or groups of endpoints without affecting the entire API, making it easier to test changes or roll out endpoint-specific features.

  • Enhance Configuration Clarity: Keep configurations clear and understandable by allowing endpoint-specific variables to be defined close to where they are used, improving maintainability and readability.

Example

Consider an API configuration where a global variable database-url is defined to point to a primary database. However, for a specific endpoint, you want to route requests to a different, endpoint-specific database. By defining a local variable database-url within the path configuration for that endpoint, the API gateway will use this local variable in preference to the global one for requests to that endpoint, ensuring that requests are routed to the correct database.

"variables": {
    "global_variable": "global_value",
    "database-url": "sqlite://primary-db.sqlite" // Global variable
},
"paths": [
    {
        "method": "GET",
        "path": "/api/v1/special-endpoint",
        "variables": {
            "database-url": "sqlite://special-db.sqlite" // Local variable takes precedence
        }
    }
]

In this setup, requests to /api/v1/special-endpoint will use sqlite://special-db.sqlite for the database-url, overriding the global setting of sqlite://primary-db.sqlite.

Conclusion

The prioritization of local variables over global variables in the Serverless API Gateway's mapping functionality provides a powerful tool for fine-tuning API behavior. It allows developers to create more specific, flexible, and maintainable API configurations, ensuring that each part of the API behaves exactly as needed without unnecessary global changes.

PreviousVariable MappingNextIntegrations

Last updated 1 year ago