pub struct Request<'a> { /* private fields */ }
Expand description

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().

Implementations

Initiate a GET request with the given URL.

Initiate a POST request with the given URL.

Initiate a PUT request with the given URL.

Initiate a PATCH request with the given URL.

Initiate a DELETE request with the given URL.

Add an HTTP header to a request.

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

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

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

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.

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.

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.

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

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();

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

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.

Add a JSON-encoded body from a serializable type.

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

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.