From b051412935bfbd8a26648ba366511d43229e8d92 Mon Sep 17 00:00:00 2001 From: Bastien Dejean Date: Fri, 6 Dec 2024 19:39:16 +0100 Subject: [PATCH] Add a method to set the URL's query from an object (#138) --- src/request/builder.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/request/builder.rs b/src/request/builder.rs index efb685b..bf327fd 100644 --- a/src/request/builder.rs +++ b/src/request/builder.rs @@ -126,6 +126,13 @@ impl RequestBuilder { self } + /// Set the query parameters of this request to be the URL-encoded representation of the given object. + #[cfg(feature = "form")] + pub fn query(mut self, value: &T) -> Result { + value.serialize(serde_urlencoded::Serializer::new(&mut self.url.query_pairs_mut()))?; + Ok(self) + } + /// Enable HTTP basic authentication. #[cfg(feature = "basic-auth")] pub fn basic_auth(self, username: impl std::fmt::Display, password: Option) -> Self {