Struct Request

Source
pub struct Request { /* private fields */ }
Expand description

Request is the main way of performing requests.

Use one of its contructors to create a request and then use the send method to send the Request and get the status, headers and response.

Implementations§

Source§

impl Request

Source

pub fn new(base_url: &str, method: Method) -> Request

Create a new Request with the base URL and the given method.

Source

pub fn get(base_url: &str) -> Request

Create a new Request with the GET method.

Source

pub fn post(base_url: &str) -> Request

Create a new Request with the POST method.

Source

pub fn put(base_url: &str) -> Request

Create a new Request with the PUT method.

Source

pub fn delete(base_url: &str) -> Request

Create a new Request with the DELETE method.

Source

pub fn head(base_url: &str) -> Request

Create a new Request with the HEAD method.

Source

pub fn options(base_url: &str) -> Request

Create a new Request with the OPTIONS method.

Source

pub fn patch(base_url: &str) -> Request

Create a new Request with the PATCH method.

Source

pub fn trace(base_url: &str) -> Request

Create a new Request with the TRACE method.

Source

pub fn param<V>(&mut self, key: &str, value: V)
where V: Display,

Associate a query string parameter to the given value.

The same key can be used multiple times.

Source

pub fn header<H, V>(&mut self, header: H, value: V) -> HttpResult
where H: IntoHeaderName, V: HttpTryInto<HeaderValue>,

Modify a header for this Request.

If the header is already present, the value will be replaced. If you wish to append a new header, use header_append.

Source

pub fn header_append<H, V>(&mut self, header: H, value: V) -> HttpResult
where H: IntoHeaderName, V: HttpTryInto<HeaderValue>,

Append a new header to this Request.

The new header is always appended to the Request, even if the header already exists.

Source

pub fn body(&mut self, body: impl AsRef<[u8]>)

Set the body of this request.

The can be a &[u8] or a str, anything that’s a sequence of bytes.

Source

pub fn follow_redirects(&mut self, follow_redirects: bool)

Sets if this Request should follow redirects, 3xx codes.

This value defaults to true.

Source

pub fn default_charset(&mut self, default_charset: Option<Charset>)

Set the default charset to use while parsing the response of this Request.

If the response does not say which charset it uses, this charset will be used to decode the request. This value defaults to None, in which case ISO-8859-1 is used.

Source

pub fn allow_compression(&mut self, allow_compression: bool)

Sets if this Request will announce that it accepts compression.

This value defaults to true. Note that this only lets the browser know that this Request supports compression, the server might choose not to compress the content.

Source

pub fn send(self) -> HttpResult<(StatusCode, HeaderMap, ResponseReader)>

Send this Request to the server.

This method consumes the object so that it cannot be used after sending the request.

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.