# API Gateway

An API gateway is an infrastructure component that sits between clients and backend services, acting as a reverse proxy that receives all API requests, applies cross-cutting policies, and routes each request to the correct upstream service. Rather than exposing backend services directly to consumers, the gateway provides a unified interface that abstracts the internal architecture.

## Core responsibilities

A typical API gateway handles several concerns that would otherwise need to be implemented in every individual service:

* **Request routing**: Matching incoming requests to the correct backend service based on the URL path, HTTP method, headers, or other attributes.
* **Authentication and authorization**: Verifying the identity of callers using mechanisms such as API keys, JWT tokens, or OAuth flows, and enforcing access policies before the request reaches the backend.
* **Protocol translation**: Accepting requests in one format and converting them for backend services that may use a different protocol or data structure.
* **Traffic management**: Applying rate limiting, request throttling, and load balancing to protect backend services from being overwhelmed.
* **Observability**: Collecting logs, metrics, and traces at the gateway level to provide a centralized view of API traffic.
* **Response transformation**: Modifying responses before returning them to the client, such as filtering fields, adding headers, or changing formats.

## Why use an API gateway

Without a gateway, each backend service must independently handle authentication, CORS, logging, and other shared concerns. This leads to duplicated logic, inconsistent policy enforcement, and a larger attack surface. A gateway centralizes these responsibilities, making it easier to maintain consistent behavior across services and reducing the amount of boilerplate code in each backend.

For microservices architectures especially, a gateway simplifies the client experience. Clients call a single endpoint rather than tracking the addresses and protocols of many individual services.

## Serverless API Gateway

Serverless API Gateway is an open-source API gateway built on Cloudflare Workers. Because it runs at the edge on Cloudflare's network, it processes requests close to end users with low latency and without requiring you to provision or manage servers. Configuration is defined declaratively, covering path-based routing, JWT authorization, CORS policies, upstream server definitions, and variable mapping between requests and backends.

Being serverless, it follows a pay-per-request model and scales automatically with traffic. It supports routing to backend services on any cloud provider, making it a practical choice for multi-cloud or hybrid architectures.

## Related documentation

* [Configuration Overview](/configuration/overview.md) - How to configure gateway behavior
* [Authorizer Configuration](/configuration/authorizer.md) - Set up JWT authentication
* [Path Routing](/configuration/paths.md) - Define routing rules for API endpoints
* [Getting Started](/getting-started/introduction.md) - Quick start guide for deploying the gateway


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.serverlessapigateway.com/glossary/a/api-gateway.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
