4 releases (1 stable)
Uses old Rust 2015
4087.0.0 | May 16, 2022 |
---|---|
0.2.2 | Feb 27, 2019 |
0.2.0 | Feb 26, 2019 |
0.1.0 | Feb 26, 2019 |
#25 in #curl
22 downloads per month
25KB
383 lines
crimp
Crimp is an HTTP client interface on top of the Rust bindings to cURL.
The documentation for this crate is primarily in the module documentation
This project is developed in the TVL monorepo. To work on it,
you can either use a local clone of the entire repository or clone
just the crimp
subtree:
https://code.tvl.fyi/depot.git:/net/crimp.git
Please follow the TVL contribution guidelines.
lib.rs
:
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
: AddsRequest::json
andResponse::as_json
methods which can be used for convenient serialisation of request/response bodies usingserde_json
. This feature adds a dependency on theserde
andserde_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.
Dependencies
~8–15MB
~215K SLoC