[][src]Struct crimp::Response

pub struct Response<T> {
    pub status: u32,
    pub headers: HashMap<String, String>,
    pub body: T,
}

HTTP responses structure containing response data and headers.

By default the send() function of the Request structure will return a Response<Vec<u8>>. Convenience helpers exist for decoding a string via Response::as_string or to a serde-compatible type with Response::as_json (if the json-feature is enabled).

Fields

status: u32

HTTP status code of the response.

headers: HashMap<String, String>

HTTP headers returned from the remote.

body: T

Body data from the HTTP response.

Methods

impl<T> Response<T>[src]

pub fn is_success(&self) -> bool[src]

Check whether the status code of this HTTP response is a success (i.e. in the 200-299 range).

pub fn error_for_status<F, E>(self, closure: F) -> Result<Self, E> where
    F: FnOnce(Self) -> E, 
[src]

Check whether a request succeeded using Request::is_success and let users provide a closure that creates a custom error from the request if it did not.

This function exists for convenience to avoid having to write repetitive if !response.is_success() { ... } blocks.

impl Response<Vec<u8>>[src]

pub fn as_string(self) -> Result<Response<String>, FromUtf8Error>[src]

Attempt to parse the HTTP response body as a UTF-8 encoded string.

pub fn as_json<T: DeserializeOwned>(self) -> Result<Response<T>, Error>[src]

Attempt to deserialize the HTTP response body from JSON.

Trait Implementations

impl<T: PartialEq> PartialEq<Response<T>> for Response<T>[src]

impl<T: Debug> Debug for Response<T>[src]

Auto Trait Implementations

impl<T> Send for Response<T> where
    T: Send

impl<T> Sync for Response<T> where
    T: Sync

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.