pub struct Response {
pub request_method: Method,
pub url: Url,
pub status: u16,
pub headers: Headers,
pub body: Vec<u8>,
}
Expand description
A response from the server.
Fields§
§request_method: Method
The method used to request this response.
url: Url
The URL of this response.
status: u16
The HTTP Status code of this response.
headers: Headers
The headers returned with this response.
body: Vec<u8>
The body of the response.
Implementations§
source§impl Response
impl Response
sourcepub fn json<'a, T>(&'a self) -> Result<T, Error>where
T: Deserialize<'a>,
pub fn json<'a, T>(&'a self) -> Result<T, Error>where
T: Deserialize<'a>,
Parse the body as JSON.
sourcepub fn text(&self) -> Cow<'_, str>
pub fn text(&self) -> Cow<'_, str>
Get the body as a string. Assumes UTF-8 encoding. Any non-utf8 bytes are replaced with the replacement character.
sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Returns true if the status code is in the interval [200, 300)
.
sourcepub fn is_server_error(&self) -> bool
pub fn is_server_error(&self) -> bool
Returns true if the status code is in the interval [500, 600)
.
sourcepub fn is_client_error(&self) -> bool
pub fn is_client_error(&self) -> bool
Returns true if the status code is in the interval [400, 500)
.
sourcepub fn require_success(self) -> Result<Self, UnexpectedStatus>
pub fn require_success(self) -> Result<Self, UnexpectedStatus>
Returns an UnexpectedStatus
error if self.is_success()
is false,
otherwise returns Ok(self)
.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Response
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnwindSafe for Response
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)