Skip to content

How to convert the body from axum request into "reqwest" body? #2603

Answered by Threated
spikeHollow asked this question in Q&A
Discussion options

You must be logged in to vote

I usually do this:

fn convert(req: axum::extract::Request) -> reqwest::Request {
    let req = req.map(|body| reqwest::Body::wrap_stream(body.into_data_stream()));
    reqwest::Request::try_from(req).expect("http::Uri to url::Url conversion failed")
}

This only works with the stream feature of reqwest.
The reqwest::Request can then be executed with reqwest::Client::execute.

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@quadruple-output
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by jplatte
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants