expression
Encode query parameters
Provide query values as data rather than interpolating them into the URL. Adding a key again appends another occurrence; it does not replace the first value. External crate example; constructs requests or synthetic responses in memory; no request is sent. Expected stdout (not executed): q: tea & cake tag: rust Common mistake: Manually joining unescaped user input with ampersands.
Formal Syntax & Structure
rust syntaxrust
builder.query(&[(key, value)])Working Example
Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() { let c = reqwest::Client::builder().no_proxy().build().unwrap(); let r = c.get("https://example.com/search").query(&[("q", "tea & cake"), ("tag", "rust")]).build().unwrap(); for (k,v) in r.url().query_pairs() { println!("{k}: {v}"); }}