pub struct Request {
pub rid: i32,
pub should_close: bool,
/* private fields */
}Expand description
An HTTP request.
Fields§
§rid: i32The reference id for the request.
This property is exposed for the functions that the register_source macro generates and should not be used directly.
should_close: boolWhether the request should be closed after being dropped.
This property is exposed for the functions that the register_source macro generates and should not be used directly.
Implementations§
Source§impl Request
impl Request
Sourcepub fn new<T: AsRef<str>>(
url: T,
http_method: HttpMethod,
) -> Result<Self, RequestError>
pub fn new<T: AsRef<str>>( url: T, http_method: HttpMethod, ) -> Result<Self, RequestError>
Sourcepub fn get<T: AsRef<str>>(url: T) -> Result<Self, RequestError>
pub fn get<T: AsRef<str>>(url: T) -> Result<Self, RequestError>
Create a new GET request with the given URL.
Sourcepub fn post<T: AsRef<str>>(url: T) -> Result<Self, RequestError>
pub fn post<T: AsRef<str>>(url: T) -> Result<Self, RequestError>
Create a new POST request with the given URL.
Sourcepub fn put<T: AsRef<str>>(url: T) -> Result<Self, RequestError>
pub fn put<T: AsRef<str>>(url: T) -> Result<Self, RequestError>
Create a new PUT request with the given URL.
Sourcepub fn head<T: AsRef<str>>(url: T) -> Result<Self, RequestError>
pub fn head<T: AsRef<str>>(url: T) -> Result<Self, RequestError>
Create a new HEAD request with the given URL.
Sourcepub fn delete<T: AsRef<str>>(url: T) -> Result<Self, RequestError>
pub fn delete<T: AsRef<str>>(url: T) -> Result<Self, RequestError>
Create a new DELETE request with the given URL.
Sourcepub fn patch<T: AsRef<str>>(url: T) -> Result<Self, RequestError>
pub fn patch<T: AsRef<str>>(url: T) -> Result<Self, RequestError>
Create a new PATCH request with the given URL.
Sourcepub fn send_all<I>(requests: I) -> Vec<Result<Response, RequestError>>where
I: IntoIterator<Item = Request>,
pub fn send_all<I>(requests: I) -> Vec<Result<Response, RequestError>>where
I: IntoIterator<Item = Request>,
Send multiple requests in parallel, and wait for all of them to finish.
Sourcepub fn set_header<T: AsRef<str>>(&mut self, key: T, val: T)
pub fn set_header<T: AsRef<str>>(&mut self, key: T, val: T)
Set an HTTP header.
Sourcepub fn timeout(self, value: f64) -> Self
pub fn timeout(self, value: f64) -> Self
Set the request timeout interval in a builder.
The request timeout interval controls how long (in seconds) a task should wait for additional data to arrive before giving up.
Sourcepub fn set_timeout(&mut self, value: f64)
pub fn set_timeout(&mut self, value: f64)
Set the request timeout interval.
The request timeout interval controls how long (in seconds) a task should wait for additional data to arrive before giving up.
Sourcepub fn set_url<T: AsRef<str>>(&mut self, url: T) -> Result<(), RequestError>
pub fn set_url<T: AsRef<str>>(&mut self, url: T) -> Result<(), RequestError>
Set the URL for the request.
Sourcepub fn send(self) -> Result<Response, RequestError>
pub fn send(self) -> Result<Response, RequestError>
Send the request.
Sourcepub fn data(self) -> Result<Vec<u8>, RequestError>
pub fn data(self) -> Result<Vec<u8>, RequestError>
Get the raw data from the response, closing the request.
Sourcepub fn image(self) -> Result<ImageRef, RequestError>
pub fn image(self) -> Result<ImageRef, RequestError>
Gets the response data as an image.
Sourcepub fn string(self) -> Result<String, AidokuError>
pub fn string(self) -> Result<String, AidokuError>
Gets the response data as a string.