#http #request #client

chttp

The practical HTTP client that is fun to use

17 unstable releases (3 breaking)

✓ Uses Rust 2018 edition

0.4.4 Jun 14, 2019
0.4.2 Apr 5, 2019
0.4.1 Feb 28, 2019
0.3.0 Dec 6, 2018
0.1.2 Dec 28, 2017

#14 in HTTP client

Download history 41/week @ 2019-03-01 10/week @ 2019-03-08 21/week @ 2019-03-15 54/week @ 2019-03-22 4/week @ 2019-03-29 46/week @ 2019-04-05 25/week @ 2019-04-12 23/week @ 2019-04-19 18/week @ 2019-04-26 25/week @ 2019-05-03 60/week @ 2019-05-10 67/week @ 2019-05-17 92/week @ 2019-05-24 12/week @ 2019-05-31 112/week @ 2019-06-07

187 downloads per month

MIT license

88KB
1.5K SLoC

cHTTP

The practical HTTP client that is fun to use.

Crates.io Documentation License

cHTTP provides a clean and easy-to-use interface around the venerable libcurl. Here are some of the features that are currently available:

  • HTTP/2 support.
  • Connection pooling and reuse.
  • Sessions and cookie persistence.
  • Response body streaming.
  • Request body uploading from memory or a stream.
  • Tweakable redirect policy.
  • Persistent cookies across requests.
  • TCP socket configuration.
  • Uses the future standard Rust http interface for requests and responses.

Documentation

Check out the documentation for details on how to use cHTTP.

Why libcurl?

Not everything needs to be re-invented! For typical use cases, libcurl is a fantastic choice for making web requests. It's fast, reliable, well supported, and isn't going away any time soon.

It has a reputation for having an unusual API that is sometimes tricky to use, but hey, that's why this library exists.

Examples

Really simple example that spits out the response body from https://example.org:

let mut response = chttp::get("https://example.org").unwrap();
let body = response.body_mut().text().unwrap();
println!("{}", body);

Configuring a custom client:

use chttp::{http, Client, Options, RedirectPolicy};
use std::time::Duration;

let mut options = Options::default();
options.timeout = Some(Duration::from_secs(60));
options.redirect_policy = RedirectPolicy::Limit(10);
options.preferred_http_version = Some(http::Version::HTTP_2);

let client = Client::builder()
    .max_connections(Some(4))
    .options(options)
    .build();

let mut response = client.get("https://example.org").unwrap();
let body = response.body_mut().text().unwrap();
println!("{}", body);

Installation

Add this to your Cargo.toml file:

[dependencies]
chttp = "0.3"

License

This library is licensed under the MIT license. See the LICENSE file for details.

Dependencies

~16MB
~324K SLoC