Struct tauri::api::http::HttpRequestBuilder

source ·
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§

source§

impl HttpRequestBuilder

source

pub fn new(method: impl Into<String>, url: impl AsRef<str>) -> Result<Self>

Initializes a new instance of the HttpRequestrequest_builder.

source

pub fn query(self, query: HashMap<String, String>) -> Self

Sets the request parameters.

source

pub fn header<K, V>(self, key: K, value: V) -> Result<Self>

Adds a header.

source

pub fn headers(self, headers: HeaderMap) -> Self

Sets the request headers.

source

pub fn body(self, body: Body) -> Self

Sets the request body.

source

pub fn timeout(self, timeout: Duration) -> Self

Sets the general request timeout.

source

pub fn response_type(self, response_type: ResponseType) -> Self

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

Trait Implementations§

source§

impl Debug for HttpRequestBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for HttpRequestBuilder

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<'de, D, R> CommandArg<'de, R> for D
where D: Deserialize<'de>, R: Runtime,

source§

fn from_command(command: CommandItem<'de, R>) -> Result<D, InvokeError>

Derives an instance of Self from the CommandItem. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,