Skip to content

struct

Request

pub struct Request {
    pub method: Method,
    pub url: String,
    pub headers: Vec<(String, String)>,
    pub body: Option<String>,
    pub binary: bool,
}

An HTTP request, ready to send.

Fields

method

pub method: Method

The method.

url

pub url: String

The full URL.

headers

pub headers: Vec<(String, String)>

Headers as (name, value) pairs.

body

pub body: Option<String>

The body, if any.

binary

pub binary: bool

The response is binary: its bytes come back one to a char.

Methods

new

pub fn new(method: Method, url: impl Into<String>) -> Request

A request with method to url, with no headers or body.

get

pub fn get(url: impl Into<String>) -> Request

A GET request to url.

post

pub fn post(url: impl Into<String>) -> Request

A POST request to url.

header

pub fn header(self, name: &str, value: impl Into<String>) -> Request

Add (or replace) a header.

bearer

pub fn bearer(self, token: &str) -> Request

The request with an Authorization: Bearer header.

json

pub fn json(self, body: &Value) -> Request

A JSON body (and its content type).

header_value

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

The value of header name (in any case), if set.

Trait implementations