Request

Struct Request 

Source
pub struct Request {
    pub rid: i32,
    pub should_close: bool,
    /* private fields */
}
Expand description

An HTTP request.

Fields§

§rid: i32

The 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: bool

Whether 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

Source

pub fn new<T: AsRef<str>>( url: T, http_method: HttpMethod, ) -> Result<Self, RequestError>

Create a new request with a URL and HTTP method.

Returns an error if the provided URL is invalid.

§Examples
use aidoku::imports::net::{HttpMethod, Request};
Request::new("https://example.com", HttpMethod::Get).unwrap();
Source

pub fn get<T: AsRef<str>>(url: T) -> Result<Self, RequestError>

Create a new GET request with the given URL.

Source

pub fn post<T: AsRef<str>>(url: T) -> Result<Self, RequestError>

Create a new POST request with the given URL.

Source

pub fn put<T: AsRef<str>>(url: T) -> Result<Self, RequestError>

Create a new PUT request with the given URL.

Source

pub fn head<T: AsRef<str>>(url: T) -> Result<Self, RequestError>

Create a new HEAD request with the given URL.

Source

pub fn delete<T: AsRef<str>>(url: T) -> Result<Self, RequestError>

Create a new DELETE request with the given URL.

Source

pub fn patch<T: AsRef<str>>(url: T) -> Result<Self, RequestError>

Create a new PATCH request with the given URL.

Source

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.

Source

pub fn header<T: AsRef<str>>(self, key: T, val: T) -> Self

Set an HTTP header in a builder.

Source

pub fn set_header<T: AsRef<str>>(&mut self, key: T, val: T)

Set an HTTP header.

Source

pub fn body<T: AsRef<[u8]>>(self, data: T) -> Self

Set the HTTP body data in a builder.

Source

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.

Source

pub fn set_body<T: AsRef<[u8]>>(&mut self, data: T)

Set the HTTP body data.

Source

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.

Source

pub fn set_url<T: AsRef<str>>(&mut self, url: T) -> Result<(), RequestError>

Set the URL for the request.

Source

pub fn url(&self) -> Option<&String>

Get the URL of the request.

Source

pub fn send(self) -> Result<Response, RequestError>

Send the request.

Source

pub fn data(self) -> Result<Vec<u8>, RequestError>

Get the raw data from the response, closing the request.

Source

pub fn image(self) -> Result<ImageRef, RequestError>

Gets the response data as an image.

Source

pub fn string(self) -> Result<String, AidokuError>

Gets the response data as a string.

Source

pub fn html(self) -> Result<Document, RequestError>

Get the response data as an HTML Document.

Trait Implementations§

Source§

impl Debug for Request

Source§

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

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

impl Drop for Request

Source§

fn drop(&mut self)

Executes the destructor for this type. 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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.