[−][src]Struct crimp::Response
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]
F: FnOnce(Self) -> E,
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
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,