Creating a reqwest Request without a builder
⚓ Rust 📅 2025-07-29 👤 surdeus 👁️ 12After a lot of reading and practicing exercises, I'm now writing my first real-world Rust program, a testing utility for a website search engine.
I've started out prototyping with reqwests. The easy way to do this is using the RequestBuilder, but I'm a TDD guy and would like to write my tests without out-of-process dependencies. I've come up with the code below (not a test, just rewritten as simply as possible) for exercising an endpoint. The main thing I struggled with is setting the body.
Any suggestions and criticism are welcome!
use reqwest::Url;
use reqwest::blocking::{Body, Request};
fn main() {
let params = vec![("teeth", "pointy"), ("venom", "deadly")];
let url = Url::parse_with_params("http://reptiles.com", params).unwrap();
let mut request = Request::new(reqwest::Method::POST, url);
let body = request.body_mut();
*body = Some(Body::from("The body content".to_string()));
}
1 post - 1 participant
🏷️ Rust_feed