Skip to content
Discussion options

You must be logged in to vote

The Service trait allows for handling the request and the response. For instance, if using a closure:

service_fn(|req| {
    let inner_fut = inner.call(req);
    async move {
        let resp = inner_fut.await?;
        Ok(transform_resp(resp))
    }
});

You can do similarly with impl<Req> Service<Req>, or with Layer.

There's several examples, such as in tower-http, here's just one of many: https://docs.rs/tower-http/latest/tower_http/map_response_body/index.html

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ThomasCartier
Comment options

Answer selected by ThomasCartier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants