Expand description
Tower middleware building blocks for api-bones services.
Provides composable Tower Layer / Service
implementations for:
| Layer | What it does |
|---|---|
RequestIdLayer | Generates / propagates X-Request-Id on every req |
ProblemJsonLayer | Maps non-ApiError inner-service errors to Problem+JSON |
§Feature flags
By default this crate enables std and serde on api-bones.
Additional api-bones features can be opted into:
| Feature | What it enables |
|---|---|
uuid | UUID-based request IDs (api-bones/uuid) |
chrono | Chrono timestamp types (api-bones/chrono) |
§Example
use api_bones_tower::{RequestIdLayer, ProblemJsonLayer};
use tower::ServiceBuilder;
let _svc = ServiceBuilder::new()
.layer(RequestIdLayer::new())
.layer(ProblemJsonLayer::new())
.service(tower::service_fn(|_req: http::Request<()>| async {
Ok::<_, std::convert::Infallible>(http::Response::new(()))
}));Structs§
- Problem
Json Layer - Tower
Layerthat maps inner-service errors into Problem+JSON HTTP responses. - Problem
Json Service - Tower
Serviceproduced byProblemJsonLayer. - Request
IdFuture - Future returned by
RequestIdService. - Request
IdLayer - Tower
Layerthat ensures every request carries anX-Request-Idheader. - Request
IdService - Tower
Serviceproduced byRequestIdLayer.