Expand description
§Gateway Runtime
§Overview
The gateway-runtime crate provides the essential runtime components for the grpc-gateway-rust ecosystem.
It acts as the bridge between HTTP/JSON requests and gRPC services, handling routing, transcoding,
authentication, and middleware orchestration.
§Core Components
- Gateway: The primary builder and entry point. It orchestrates the middleware stack and constructs
the final
tower::Serviceresponsible for handling requests. - Router: Manages the registration and matching of gRPC service methods to HTTP paths.
- Codec: Handles the transcoding between HTTP body formats (JSON) and Protocol Buffers.
- errors::GatewayError: The canonical error type for the gateway, mapping gRPC status codes to HTTP responses.
§Middleware Architecture
The gateway uses tower::Service layers to compose functionality. The execution order for an incoming request is:
- Tracing/Metrics: Telemetry recording.
- Error Handling: Catches internal or upstream errors and formats them (e.g., as JSON).
- Response Modification: Late-stage modification of HTTP responses.
- Header Processing: Filtering and renaming of incoming/outgoing headers.
- Metadata Extraction: Converting headers or context into gRPC metadata.
- Routing & Auth: Matching the path and verifying authentication requirements.
- Dispatch: Invoking the generated service handler.
§Feature Flags
std(default): Enables standard library features (e.g.,std::error::ErrorforGatewayError). Disable this forno_stdenvironments (requiresalloc).
§Integration
This crate is typically used by code generated by protoc-gen-grpc-gateway-rust, but can also be used
manually to build custom gateways.
Re-exports§
pub use codec::Codec;pub use errors::GatewayError;pub use gateway::Gateway;pub use gateway::UnescapingMode;pub use router::Router;pub use bytes;pub use http;pub use http_body;pub use http_body_util;pub use tonic;pub use tower;
Modules§
- codec
- Codec
- defaults
- Default Handlers
- errors
- Errors
- forward
- Forward
- gateway
- Gateway Builder and Service
- handlers
- Custom Handlers
- layers
- Middleware Layers
- metadata
- Metadata
- router
- Router
- shutdown
- Shutdown
- utilities
- Utilities
Type Aliases§
- BoxBody
- A boxed body that implements
http_body::Body. - Boxed
Gateway Service - A boxed cloneable service for handling gateway requests.
- Gateway
Request - A generic HTTP request body for the gateway.
- Gateway
Response - A generic HTTP response body for the gateway.
- Gateway
Result - A generic Result type for gateway operations.