Request

Struct Request 

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

HTTP request

A request is composed of:

  • HTTP method (GET, POST, PUT, DELETE, … )
  • Target URL, for example, https://myservice.com/users
  • (optional) Request headers.
  • (optional) Request path parameters, for example, id in the URL https://myservice.com/users?id=1111.
  • (optional) Server cookies
  • (optional) Request body

Request headers, parameters and cookies are represented by a pair of name and value strings.

For more information see HTTP Request.

Implementations§

Source§

impl Request

Source

pub fn new<S>(method: HttpMethod, url: S) -> Request
where S: Into<String>,

Hidden constructor

Source

pub fn connect<S>(url: S) -> Request
where S: Into<String>,

Creates a CONNECT request builder

Source

pub fn delete<S>(url: S) -> Request
where S: Into<String>,

Creates a DELETE request builder

Source

pub fn get<S>(url: S) -> Request
where S: Into<String>,

Creates a GET request builder

Source

pub fn head<S>(url: S) -> Request
where S: Into<String>,

Creates a HEAD request builder

Source

pub fn options<S>(url: S) -> Request
where S: Into<String>,

Creates a OPTIONS request builder

Source

pub fn patch<S>(url: S) -> Request
where S: Into<String>,

Creates a PATCH request builder

Source

pub fn post<S>(url: S) -> Request
where S: Into<String>,

Creates a POST request builder

Source

pub fn put<S>(url: S) -> Request
where S: Into<String>,

Creates a PUT request builder

Source

pub fn trace<S>(url: S) -> Request
where S: Into<String>,

Creates a TRACE request builder

Source

pub fn method(&self) -> HttpMethod

Gets HTTP Method

Source

pub fn insert_param<K, V>(&mut self, key: K, value: V) -> &mut Self
where K: Into<String>, V: Into<String>,

Insert a request param with key and value. Param keys are case-sensitive.

Source

pub fn params(&self) -> &KeyValueMap

Gets a params map reference

Source

pub fn params_mut(&mut self) -> &mut KeyValueMap

Gets a mutable params map reference

Insert a cookie param with key and value. Param keys are case-sensitive.

Source

pub fn cookies(&self) -> &KeyValueMap

Gets a cookie map reference

Source

pub fn cookies_mut(&mut self) -> &mut KeyValueMap

Gets a mutable params map reference

Source

pub fn target(&self) -> &str

Gets the target URL as an string

Source

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

Gets url::Url reference if target is well-formed

Methods from Deref<Target = HttpMessage>§

Source

pub fn insert_header<K, V>(&mut self, key: K, value: V) -> &mut Self
where K: Into<String>, V: Into<String>,

Inserts a header with key and value

Source

pub fn headers(&self) -> &HeaderMap

Gets the headers map

Source

pub fn headers_mut(&mut self) -> &mut HeaderMap

Gets a mutable reference to the headers map

Source

pub fn has_single_body(&self) -> bool

Checks if the request has a single body

Source

pub fn has_multipart_body(&self) -> bool

Checks if the request has a multi-part body

Source

pub fn set_body(&mut self, data: Vec<u8>) -> &mut Self

Sets a single body

Source

pub fn body(&self) -> Option<&Vec<u8>>

Gets body data if any, returns None if there is no single body

Source

pub fn set_json(&mut self, data: &JsonValue) -> &mut Self

Sets a json object as request body. The data object is marshaled into a buffer using UTF8 coding. Returns true if request body is overriden

Source

pub fn json(&self) -> Result<JsonValue, Error>

Checks if the Response has body and tries to parse as a `json::JsonValue’

Trait Implementations§

Source§

impl Deref for Request

Source§

type Target = HttpMessage

The resulting type after dereferencing.
Source§

fn deref(&self) -> &HttpMessage

Dereferences the value.
Source§

impl DerefMut for Request

Source§

fn deref_mut(&mut self) -> &mut HttpMessage

Mutably dereferences the value.
Source§

impl Display for Request

Source§

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

Formats the value using the given formatter. 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,