Expand description
§Gateway Builder and Service
§Purpose
This module provides the Gateway builder struct, which is the primary entry point for configuring
and constructing the runtime service stack. It orchestrates the various middleware layers
(routing, authentication, error handling, metadata, etc.) into a cohesive tower::Service.
§Scope
This module defines:
Gateway: A builder for configuring the runtime.RouterService: The core service responsible for routing and authentication.UnescapingMode: Configuration for path unescaping.- Type aliases for various handler callbacks (
ErrorHandler,AuthVerifier, etc.).
§Middleware Stack
The Gateway::into_service() method constructs a tower::Service with the following layer order
(outer to inner):
- Tracing: Request/Response tracing.
- Metrics: Request duration and status recording.
- Error Handling: Catches errors from inner layers and converts them to HTTP responses.
- Response Modifiers: modifying the response before sending it back.
- Headers: Filtering/Transforming incoming and outgoing headers.
- Metadata: Extracting and injecting metadata (e.g., from headers or annotators).
- RouterService: The core logic (Path matching -> Auth -> Dispatch).
§Position in the Architecture
The Gateway is the glue that binds the Router (generated code registry) with the
runtime features (handlers, defaults). The resulting service is typically passed to
an HTTP server (like hyper).
Structs§
- Gateway
- A builder and configuration struct for the Gateway runtime.
Enums§
- Unescaping
Mode - Configuration for unescaping path parameters.
Type Aliases§
- Auth
Verifier - A handler for verifying authentication requirements.
- Error
Handler - A handler for converting errors into HTTP responses.
- Header
Matcher - A handler for matching and transforming headers.
- Metadata
Annotator - A handler for annotating requests with metadata.
- Metrics
Recorder - A handler for recording metrics.
- Response
Modifier - A handler for modifying HTTP responses before they are sent.
- Tracing
EndHandler - A handler for tracing end.
- Tracing
Start Handler - A handler for tracing start. Returns an opaque token (TraceContext) to be passed to end.