Crate crimp

source · []
Expand description

crimp

This library provides a simplified API over the cURL Rust bindings that resemble that of higher-level libraries such as reqwest. All calls are synchronous.

crimp is intended to be used in situations where HTTP client functionality is desired without adding a significant number of dependencies or sacrificing too much usability.

Using crimp to make HTTP requests is done using a simple builder-pattern style API. For example, to make a GET-request and print the result to stdout:

use crimp::Request;

let response = Request::get("http://httpbin.org/get")
    .user_agent("crimp test suite")
    .unwrap()
    .send()
    .unwrap()
    .as_string()
    .unwrap();

println!("Status: {}\nBody: {}", response.status, response.body);

If a feature from the underlying cURL library is missing, the Request::raw method can be used as an escape hatch to deal with the handle directly. Should you find yourself doing this, please file an issue.

crimp does not currently expose functionality for re-using a cURL Easy handle, meaning that keep-alive of HTTP connections and the like is not supported.

Cargo features

All optional features are enabled by default.

  • json: Adds Request::json and Response::as_json methods which can be used for convenient serialisation of request/response bodies using serde_json. This feature adds a dependency on the serde and serde_json crates.

Initialisation

It is recommended to call the underlying curl::init method (re-exported as crimp::init) when launching your application to initialise the cURL library. This is not required, but will otherwise occur the first time a request is made.

Structs

Builder structure for an HTTP request.

HTTP responses structure containing response data and headers.

Enums

Certificate types for client-certificate key pairs.

Functions

Initializes the underlying libcurl library.