Skip to content

struct

Response

pub struct Response {
    pub status: u16,
    pub headers: Vec<(String, String)>,
    pub body: String,
}

An HTTP response.

Fields

status

pub status: u16

The status code.

headers

pub headers: Vec<(String, String)>

Headers as (name, value) pairs.

body

pub body: String

The body.

Methods

new

pub fn new(status: u16, body: impl Into<String>) -> Response

A response with status and body, and no headers.

with_header

pub fn with_header(self, name: &str, value: &str) -> Response

The response with header name added.

header

pub fn header(&self, name: &str) -> Option<&str>

The value of header name (in any case), if the response has it.

is_success

pub fn is_success(&self) -> bool

Whether the status is 2xx.

json

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

The body as JSON; an error for non-2xx statuses (with the service's message when it gives one).

Trait implementations