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?;

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?;

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?;