Skip to content

Converting request body to axum::body::Body #513

Answered by davidpdrsn
Umenokin asked this question in Q&A
Discussion options

You must be logged in to vote

If you're in a spot that requires converting a generic request body into a axum::body::Body then I'd say your approach is wrong. Its not something you should have to do. So this feels like an XY question.

Is there a reason you're writing tower services directly instead of async handler functions? If that is possible I would highly recommend doing that instead as its way easier.

You also don't have to use a generic parameter for the request body. Doing this should just work:

impl<S> Service<Request<Body>> for Foo<S>
where
    S: Service<Request<Body>>,

Similar to whats shown here.

This wont work if you have middleware the change the request body but such middleware are very rare. For examp…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Umenokin
Comment options

@davidpdrsn
Comment options

Answer selected by Umenokin
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