Struct http::RequestBuilder

Overview

A builder to construct the properties of a Request.

To construct a RequestBuilder, refer to the Client documentation.

Methods

async fn send(self) -> Result

Send the request and receive an answer from the server.

let client = http::Client::new();

let response = client.get("http://example.com")
   .header("Accept", "text/html")
   .send()
   .await?;

let response = response.text().await?;
fn header(self, key: String, value: String) -> RequestBuilder

Modify a header in the request.

let client = http::Client::new();

let response = client.get("http://example.com")
   .header("Accept", "text/html")
   .send()
   .await?;

let response = response.text().await?;
fn basic_auth(self, username: String, password: Option) -> RequestBuilder

Enable basic authentication in the request.

let client = http::Client::new();

let response = client.get("http://example.com")
   .basic_auth("admin", Some("good password"))
   .send()
   .await?;

let response = response.text().await?;

Enable bearer authentication in the request.

let client = http::Client::new();

let response = client.get("http://example.com")
   .bearer_auth("A1B2C3D4E5")
   .send()
   .await?;

let response = response.text().await?;

Disable CORS on fetching the request.

This option is only effective with WebAssembly target. The [request mode][mdn] will be set to 'no-cors'. [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/Request/mode

let client = http::Client::new();

let response = client.get("http://example.com")
   .fetch_mode_no_cors()
   .send()
   .await?;

let response = response.text().await?;

Set the request body from bytes.

let client = http::Client::new();

let response = client.get("http://example.com")
   .body_bytes(b"Hello World")
   .send()
   .await?;

let response = response.text().await?;