RequestBuilder

Struct RequestBuilder 

Source
pub struct RequestBuilder { /* private fields */ }
Expand description

Helper builder for Request

  • The Request builder has a constructor for each HTTP method (get, post, put, …) and a set of member functions to set the request members.
  • A build function creates Request.
use wclient::RequestBuilder;
use json::object;
let data = object! {
   name: "John",
   surname: "Smith"
};
 
let mut request = RequestBuilder::post("Http://web.myservice.com/user")
    .header("Accept", "application/json")
    .param("id", "12345")
    .json(&data)
    .build();

Implementations§

Source§

impl RequestBuilder

Source

pub fn new<S>(method: HttpMethod, url: S) -> RequestBuilder
where S: Into<String>,

Default constructor

Source

pub fn connect<S>(url: S) -> RequestBuilder
where S: Into<String>,

Creates a CONNECT request builder

Source

pub fn delete<S>(url: S) -> RequestBuilder
where S: Into<String>,

Creates a DELETE request builder

Source

pub fn get<S>(url: S) -> RequestBuilder
where S: Into<String>,

Creates a GET request builder

Source

pub fn head<S>(url: S) -> RequestBuilder
where S: Into<String>,

Creates a HEAD request builder

Source

pub fn options<S>(url: S) -> RequestBuilder
where S: Into<String>,

Creates a OPTIONS request builder

Source

pub fn patch<S>(url: S) -> RequestBuilder
where S: Into<String>,

Creates a PATCH request builder

Source

pub fn post<S>(url: S) -> RequestBuilder
where S: Into<String>,

Creates a POST request builder

Source

pub fn put<S>(url: S) -> RequestBuilder
where S: Into<String>,

Creates a PUT request builder

Source

pub fn trace<S>(url: S) -> RequestBuilder
where S: Into<String>,

Creates a TRACE request builder

Source

pub fn config(self, data: &HttpConfig) -> RequestBuilder

Sets the Request configuration

Source

pub fn headers(self, data: HashMap<String, String>) -> RequestBuilder

Adds a set of headers. If there is an existing header with the same key, it is overrriden.

Note: header names are case-insensitive.

Source

pub fn header<S>(self, name: S, value: S) -> RequestBuilder
where S: Into<String>,

Adds a header. If there is an existing header with the same `name’, it is overrriden.

Note: header names are case-insensitive.

Source

pub fn params(self, data: HashMap<String, String>) -> RequestBuilder

Adds a set of parameters. If there is an existing parameter with the same key, it is overrriden.

Note: parameter names are case-sensitive.

Source

pub fn param<S>(self, name: S, value: S) -> RequestBuilder
where S: Into<String>,

Adds a parameter. If there is an existing parameter with the same key, it is overrriden.

Note: parameter names are case-sensitive.

Source

pub fn cookies(self, data: HashMap<String, String>) -> RequestBuilder

Adds a set of cookies. If there is an existing cookie with the same key, it is overrriden.

Note: cookie names are case-sensitive.

Source

pub fn cookie<S>(self, name: S, value: S) -> RequestBuilder
where S: Into<String>,

Adds a cookie. If there is an existing cookie with the same key, it is overrriden.

Note: cookie names are case-sensitive.

Source

pub fn cookie_jar(self, jar: Arc<Mutex<dyn CookieJar>>) -> RequestBuilder

Sets a CookieJar to get/save session cookies

Source

pub fn body(self, data: Vec<u8>) -> RequestBuilder

Sets a request body. The Request takes ownership of the data buffer.

Source

pub fn json(self, data: &JsonValue) -> RequestBuilder

Sets a json object as request body. The data object is marshaled into a buffer using UTF8 coding.

Source

pub fn auth(self, mgr: Arc<Mutex<dyn AuthManager>>) -> RequestBuilder

Sets Connection Authenticator for 401 Not Authorized responses with WWW-Authenticate headers

Source

pub fn build(self) -> Request

Creates a Request struct.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.