# API Gateway

The Gateway is an API Gateway application that runs within Watt (the Node.js Application Server). It automatically integrates multiple microservices into a unified API ecosystem, providing a single public endpoint for clients while managing routing, composition, and conflict resolution behind the scenes.

The Gateway aggregates APIs from multiple sources - whether they're other applications in your Watt application, external APIs, or legacy systems - presenting them as a cohesive, well-documented API to your clients.

For a high level overview of how Watt and its applications work, please reference the [Overview](/docs/latest/Overview/) guide.

:::info[Previously called Composer]

Gateway was named **Composer** throughout the v1 and v2 lines, and was distributed as `@platformatic/composer`. It was renamed to Gateway in **v3.0.0**; the documentation, the package name, and the configuration key all use `gateway` from that release onward.

`@platformatic/composer` still exists in v3 as a deprecated alias that re-exports Gateway, so existing applications keep working, but it logs a deprecation warning on startup and **will be removed in v4.0.0**.

To migrate:

- Replace the `@platformatic/composer` dependency with `@platformatic/gateway`
- Point `$schema` at `https://schemas.platformatic.dev/@platformatic/gateway/<version>.json`
- Rename the top-level `composer` configuration key to `gateway`

The properties nested under that key are unchanged, so no other edits are needed.

:::

## Features

- **Service Discovery**: Automatically discover and compose APIs from multiple applications in your Watt application
- **OpenAPI Composition**: Combine multiple OpenAPI specifications into a single, unified API documentation
- **GraphQL Federation**: Aggregate GraphQL schemas from multiple applications with Apollo Federation support
- **Conflict Resolution**: Intelligent handling of endpoint conflicts and path overlaps between applications
- **Route Prefixing**: Organize APIs with automatic or custom path prefixing for each application
- **Flexible Proxy Routing**: Route requests by prefix, method, and path patterns when multiple applications share the same prefix. See [Gateway configuration](/docs/latest/reference/gateway/configuration/#gateway).
- **Request Deduplication**: Collapse concurrent matching proxied requests before they reach upstream applications. See [Request Deduplication](/docs/latest/reference/gateway/deduplication/).
- **Dynamic Updates**: Real-time schema updates when underlying applications change (in development mode)
- **Custom Logic**: Extend with Fastify plugins for authentication, rate limiting, or request transformation

## When to Use the Gateway

The Gateway is ideal for:

- **Microservices Architecture**: Present a unified API from multiple independent services
- **API Aggregation**: Combine internal and external APIs into a single public interface
- **Legacy Integration**: Gradually modernize by composing new and legacy APIs
- **Team Boundaries**: Allow different teams to own applications while providing unified client experience
- **API Versioning**: Manage different API versions while maintaining client compatibility
- **Client Simplification**: Reduce client complexity by handling application discovery and routing

## Quick Start

Create a Gateway within a Watt application:

```bash
# Create a new Watt application
wattpm create my-gateway

# Add multiple applications to compose
# (This will prompt you through the application setup)
cd my-gateway

# Start in development mode
wattpm dev
```

Your Gateway will automatically discover other applications in your Watt application and create a unified API. Visit `http://localhost:3042/documentation` to see the composed API documentation.

For application-specific configuration and advanced usage, see the [Configuration](/docs/latest/reference/gateway/configuration/) guide.

## Command Line usage (CLI)

When using [Watt](/docs/latest/reference/wattpm/overview/), `@platformatic/gateway` applications will make some additional commands available on the terminal.

All the commands will be prefixed by the application id. For instance, if your application id is `main`, then you will have the following commands available:

- `main:fetch-openapi-schemas`: Fetch OpenAPI schemas from remote services.


# Issues

If you run into a bug or have a suggestion for improvement, please
[raise an issue on GitHub](https://github.com/platformatic/platformatic/issues/new).