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
sourceimpl HttpRequestBuilder
impl HttpRequestBuilder
sourcepub fn new(method: impl Into<String>, url: impl AsRef<str>) -> Result<Self>
pub fn new(method: impl Into<String>, url: impl AsRef<str>) -> Result<Self>
Initializes a new instance of the HttpRequestrequest_builder.
sourcepub fn header<K, V>(self, key: K, value: V) -> Result<Self> where
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<Error>,
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<Error>,
pub fn header<K, V>(self, key: K, value: V) -> Result<Self> where
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<Error>,
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<Error>,
Adds a header.
sourcepub fn response_type(self, response_type: ResponseType) -> Self
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
sourceimpl Debug for HttpRequestBuilder
impl Debug for HttpRequestBuilder
sourceimpl<'de> Deserialize<'de> for HttpRequestBuilder
impl<'de> Deserialize<'de> for HttpRequestBuilder
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
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
impl RefUnwindSafe for HttpRequestBuilder
impl Send for HttpRequestBuilder
impl Sync for HttpRequestBuilder
impl Unpin for HttpRequestBuilder
impl UnwindSafe for HttpRequestBuilder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<'de, D, R> CommandArg<'de, R> for D where
D: Deserialize<'de>,
R: Runtime,
impl<'de, D, R> CommandArg<'de, R> for D where
D: Deserialize<'de>,
R: Runtime,
sourcefn from_command(command: CommandItem<'de, R>) -> Result<D, InvokeError>
fn from_command(command: CommandItem<'de, R>) -> Result<D, InvokeError>
Derives an instance of Self
from the CommandItem
. Read more