Skip to main content

Crate api_bones_tower

Crate api_bones_tower 

Source
Expand description

Tower middleware building blocks for api-bones services.

Provides composable Tower Layer / Service implementations for:

LayerWhat it does
RequestIdLayerGenerates / propagates X-Request-Id on every req
ProblemJsonLayerMaps 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:

FeatureWhat it enables
uuidUUID-based request IDs (api-bones/uuid)
chronoChrono 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§

ProblemJsonLayer
Tower Layer that maps inner-service errors into Problem+JSON HTTP responses.
ProblemJsonService
Tower Service produced by ProblemJsonLayer.
RequestIdFuture
Future returned by RequestIdService.
RequestIdLayer
Tower Layer that ensures every request carries an X-Request-Id header.
RequestIdService
Tower Service produced by RequestIdLayer.