pub struct Response { /* private fields */ }
Expand description

A Response to a submitted Request.

Implementations

Get the StatusCode of this Response.

Get the Headers of this Response.

Get a mutable reference to the Headers of this Response.

Retrieve the cookies contained in the response.

Note that invalid ‘Set-Cookie’ headers will be ignored.

Get the final Url of this Response.

Get the remote address used to get this Response.

Get the content-length of this response, if known.

Reasons it may not be known:

  • The server didn’t send a content-length header.
  • The response is gzipped and automatically decoded (thus changing the actual decoded length).

Consumes the response, returning the body

Get a reference to the response body.

Get a mutable reference to the response body.

The chunks from the body may be decoded, depending on the gzip option on the ClientBuilder.

Get the HTTP Version of this Response.

Get the response text

Get the response text given a specific encoding

Try to deserialize the response body as JSON using serde.

Turn a response into an error if the server returned an error.

Example
fn on_response(res: Response) {
    match res.error_for_status() {
        Ok(_res) => (),
        Err(err) => {
            // asserting a 400 as an example
            // it could be any status between 400...599
            assert_eq!(
                err.status(),
                Some(reqwest::StatusCode::BAD_REQUEST)
            );
        }
    }
}

Turn a reference to a response into an error if the server returned an error.

Example
fn on_response(res: &Response) {
    match res.error_for_status_ref() {
        Ok(_res) => (),
        Err(err) => {
            // asserting a 400 as an example
            // it could be any status between 400...599
            assert_eq!(
                err.status(),
                Some(reqwest::StatusCode::BAD_REQUEST)
            );
        }
    }
}

Trait Implementations

Formats the value using the given formatter. Read more

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.