How to convert the body from axum request into "reqwest" body? #2603
-
SummaryI'm trying to convert the body received from axum Request as body to reqwest client. But, when I do req.body(), it gives just &Body which doesn't give any info about type of Body. axum version0.7.4 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Basically what https://github.com/tokio-rs/axum/blob/main/examples/reqwest-response/src/main.rs does |
Beta Was this translation helpful? Give feedback.
-
You need to |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
I usually do this:
This only works with the
stream
feature ofreqwest
.The
reqwest::Request
can then be executed withreqwest::Client::execute
.