Skip to content

Commit

Permalink
Improve RequestBuilder.form() docs (#1490)
Browse files Browse the repository at this point in the history
  • Loading branch information
nihaals committed Mar 3, 2022
1 parent 0170947 commit f889a7b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/async_impl/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(&params)
/// .send()
/// .await?;
/// # Ok(())
/// # }
/// ```
///
/// # Errors
///
/// This method fails if the passed value cannot be serialized into
/// url encoded format
pub fn form<T: Serialize + ?Sized>(mut self, form: &T) -> RequestBuilder {
let mut error = None;
if let Ok(ref mut req) = self.request {
Expand Down
9 changes: 9 additions & 0 deletions src/wasm/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Serialize + ?Sized>(mut self, form: &T) -> RequestBuilder {
let mut error = None;
if let Ok(ref mut req) = self.request {
Expand Down

0 comments on commit f889a7b

Please sign in to comment.