[][src]Struct crimp::Request

pub struct Request<'a> { /* fields omitted */ }

Builder structure for an HTTP request.

This is the primary API-type in crimp. After creating a new request its parameters are modified using the various builder methods until it is consumed by send().

Methods

impl<'a> Request<'a>[src]

pub fn get(url: &'a str) -> Self[src]

Initiate a GET request with the given URL.

pub fn post(url: &'a str) -> Self[src]

Initiate a POST request with the given URL.

pub fn put(url: &'a str) -> Self[src]

Initiate a PUT request with the given URL.

pub fn patch(url: &'a str) -> Self[src]

Initiate a PATCH request with the given URL.

pub fn delete(url: &'a str) -> Self[src]

Initiate a DELETE request with the given URL.

pub fn header(self, k: &str, v: &str) -> Result<Self, Error>[src]

Add an HTTP header to a request.

pub fn user_agent(self, agent: &str) -> Result<Self, Error>[src]

Set the User-Agent for this request. By default this will be set to cURL's standard user agent.

pub fn bearer_auth(self, token: &str) -> Result<Self, Error>[src]

Set the Authorization header to a Bearer value with the supplied token.

pub fn basic_auth(self, username: &str, password: &str) -> Result<Self, Error>[src]

Set the Authorization header to a basic authentication value from the supplied username and password.

pub fn tls_client_cert<P: AsRef<Path>>(
    self,
    cert_type: CertType,
    cert: P
) -> Result<Self, Error>
[src]

Configure a TLS client certificate on the request.

Depending on whether the certificate file contains the private key or not, calling tls_client_key may be required in addition.

Consult the documentation for the ssl_cert and ssl_key functions in curl::easy::Easy2 for details on supported formats and defaults.

pub fn tls_client_key<P: AsRef<Path>>(self, key: P) -> Result<Self, Error>[src]

Configure a TLS client certificate key on the request.

Note that this does not need to be called again for PKCS12-encoded key pairs which are set via tls_client_cert.

Currently only PEM-encoded key files are supported.

pub fn tls_key_password(self, password: &str) -> Result<Self, Error>[src]

Configure an encryption password for a TLS client certificate key on the request.

This is required in case of an encrypted private key that should be used.

pub fn timeout(self, timeout: Duration) -> Result<Self, Error>[src]

Configure a timeout for the request after which the request will be aborted.

pub fn with_handle<F>(self, function: F) -> Result<Self, Error> where
    F: FnOnce(&mut Easy) -> Result<(), Error>, 
[src]

Set custom configuration on the cURL Easy handle.

This function can be considered an "escape-hatch" from the high-level API which lets users access the internal curl::easy::Easy handle and configure options on it directly.

let response = Request::get("https://httpbin.org/get")
    .with_handle(|mut handle| handle.referer("Example-Referer")).unwrap()
    .send().unwrap();

pub fn body(self, content_type: &'a str, data: &'a [u8]) -> Self[src]

Add a byte-array body to a request using the specified Content-Type.

pub fn form(self, form: Form) -> Self[src]

Add a form-encoded body to a request using the curl::Form type.

use curl::easy::Form;

let mut form = Form::new();
form.part("some-name")
    .contents("some-data".as_bytes())
    .add().unwrap();

let response = Request::post("https://httpbin.org/post")
    .user_agent("crimp test suite").unwrap()
    .form(form)
    .send().unwrap();

See the documentation of curl::easy::Form for details on how to construct a form body.

pub fn json<T: Serialize>(self, body: &T) -> Result<Self, Error>[src]

Add a JSON-encoded body from a serializable type.

pub fn send(self) -> Result<Response<Vec<u8>>, Error>[src]

Send the HTTP request and return a response structure containing the raw body.

Auto Trait Implementations

impl<'a> !Send for Request<'a>

impl<'a> !Sync for Request<'a>

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.