⚡
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
  • Overview
  • How Mapping Works
  • Configuration Example
  • Conclusion
Edit on GitHub
  1. Configuration

Variable Mapping

The Serverless API Gateway introduces a flexible and powerful way to manipulate API requests and responses dynamically through mapping configurations. This document outlines how the mapping functional

Overview

Variable mapping in the Serverless API Gateway allows for the transformation of request attributes before they reach the intended endpoint. This process involves modifying request headers and query parameters based on dynamic values derived from the request itself, JWT payload, configuration variables, or global variables. Such transformations are crucial for implementing custom logic, enriching requests with additional data, and ensuring seamless integration between different parts of your API ecosystem.

How Mapping Works

The mapping functionality is implemented through the mapping configs, which takes a request and variables and applies specified mappings to its headers and query parameters. This process consists of two main steps: resolving the dynamic values based on the mapping configuration and updating the request with these resolved values.

Resolving Dynamic Values

Dynamic values in the mapping configuration are specified with templates that reference different sources, such as request headers, JWT payload, configuration variables, or global variables. The resolveValue function parses these templates, extracts the required values from the appropriate sources, and returns the resolved values to be used in the request transformation.

Template Syntax

  • $request.header.[headerName]: Retrieves a value from the request headers.

  • $request.jwt.[claimName]: Retrieves a value from the decoded JWT payload.

  • $config.[variableName]: Retrieves a value from the configuration variables defined in the API gateway config.

  • $request.query.[parameterName]: Retrieves a value from the query parameters of the request.

Applying Mappings

Mappings can be applied to both request headers and query parameters:

  • Headers Mapping: For each entry in the headers mapping configuration, the Serverless API Gateway function resolves the specified template to a value and sets this value in the request's headers.

  • Query Parameters Mapping: Similar to headers, for each entry in the query mapping configuration, the Serverless API Gateway resolves the specified template to a value and adds or updates this value in the request's query parameters.

Configuration Example

The mapping configuration is part of the API gateway configuration file, under the paths section. Here is a simplified example showing how mappings can be configured:

"paths": [
    {
        "method": "GET",
        "path": "/api/v1/example",
        "integration": {
            "type": "http_proxy",
            "server": "serverlessapigateway-api"
        },
        "auth": true,
        "mapping": {
            "headers": {
                "x-custom-header": "$request.jwt.customClaim"
            },
            "query": {
                "user": "$request.query.userId"
            }
        },
        "variables": {
            "api_key": "API_KEY_VALUE"
        }
    }
]

In this example, a custom header x-custom-header is added to the request, with its value set to a custom claim from the JWT payload. Additionally, a query parameter user is set based on the userId query parameter in the original request.

Conclusion

The mapping functionality in the Serverless API Gateway offers a powerful mechanism for dynamically manipulating API requests. By utilizing templates to resolve values from various sources, developers can implement sophisticated logic to transform requests on the fly, ensuring that the API gateway can efficiently handle the diverse needs of modern web applications.

PreviousCORSNextPriority Variables

Last updated 1 year ago