From f889a7b6a7696823a0f3945d1360543676c79a75 Mon Sep 17 00:00:00 2001 From: Nihaal Sangha Date: Thu, 3 Mar 2022 23:00:12 +0000 Subject: [PATCH] Improve `RequestBuilder.form()` docs (#1490) --- src/async_impl/request.rs | 26 ++++++++++++++++++++++++++ src/wasm/request.rs | 9 +++++++++ 2 files changed, 35 insertions(+) diff --git a/src/async_impl/request.rs b/src/async_impl/request.rs index f11e75638..62744b36c 100644 --- a/src/async_impl/request.rs +++ b/src/async_impl/request.rs @@ -375,6 +375,32 @@ impl RequestBuilder { } /// Send a form body. + /// + /// Sets the body to the url encoded serialization of the passed value, + /// and also sets the `Content-Type: application/x-www-form-urlencoded` + /// header. + /// + /// ```rust + /// # use reqwest::Error; + /// # use std::collections::HashMap; + /// # + /// # async fn run() -> Result<(), Error> { + /// let mut params = HashMap::new(); + /// params.insert("lang", "rust"); + /// + /// let client = reqwest::Client::new(); + /// let res = client.post("http://httpbin.org") + /// .form(¶ms) + /// .send() + /// .await?; + /// # Ok(()) + /// # } + /// ``` + /// + /// # Errors + /// + /// This method fails if the passed value cannot be serialized into + /// url encoded format pub fn form(mut self, form: &T) -> RequestBuilder { let mut error = None; if let Ok(ref mut req) = self.request { diff --git a/src/wasm/request.rs b/src/wasm/request.rs index a939cc7fd..b3d45a046 100644 --- a/src/wasm/request.rs +++ b/src/wasm/request.rs @@ -156,6 +156,15 @@ impl RequestBuilder { } /// Send a form body. + /// + /// Sets the body to the url encoded serialization of the passed value, + /// and also sets the `Content-Type: application/x-www-form-urlencoded` + /// header. + /// + /// # Errors + /// + /// This method fails if the passed value cannot be serialized into + /// url encoded format pub fn form(mut self, form: &T) -> RequestBuilder { let mut error = None; if let Ok(ref mut req) = self.request {