pub struct HttpRequestBuilder {
    pub method: String,
    pub url: Url,
    pub query: Option<HashMap<String, String>>,
    pub headers: Option<HeaderMap>,
    pub body: Option<Body>,
    pub timeout: Option<Duration>,
    pub response_type: Option<ResponseType>,
}
Available on crate feature http-api only.
Expand description

The builder for a HTTP request.

Examples

use tauri::api::http::{HttpRequestBuilder, ResponseType, ClientBuilder};
async fn run() {
  let client = ClientBuilder::new()
    .max_redirections(3)
    .build()
    .unwrap();
  let request = HttpRequestBuilder::new("GET", "http://example.com").unwrap()
    .response_type(ResponseType::Text);
  if let Ok(response) = client.send(request).await {
    println!("got response");
  } else {
    println!("Something Happened!");
  }
}

Fields

method: String

The request method (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS, CONNECT or TRACE)

url: Url

The request URL

query: Option<HashMap<String, String>>

The request query params

headers: Option<HeaderMap>

The request headers

body: Option<Body>

The request body

timeout: Option<Duration>

Timeout for the whole request

response_type: Option<ResponseType>

The response type (defaults to Json)

Implementations

Initializes a new instance of the HttpRequestrequest_builder.

Sets the request parameters.

Adds a header.

Sets the request headers.

Sets the request body.

Sets the general request timeout.

Sets the type of the response. Interferes with the way we read the response.

Trait Implementations

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Derives an instance of Self from the CommandItem. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.