27 releases

0.5.5 Aug 3, 2019
0.5.3 Jul 26, 2019
0.4.1 Feb 28, 2019
0.3.0 Dec 6, 2018
0.1.2 Dec 28, 2017

#305 in HTTP client

Download history 109/week @ 2024-02-26 103/week @ 2024-03-04 98/week @ 2024-03-11 47/week @ 2024-03-18 74/week @ 2024-03-25 107/week @ 2024-04-01 80/week @ 2024-04-08 133/week @ 2024-04-15 110/week @ 2024-04-22 69/week @ 2024-04-29 152/week @ 2024-05-06 125/week @ 2024-05-13 92/week @ 2024-05-20 117/week @ 2024-05-27 119/week @ 2024-06-03 100/week @ 2024-06-10

431 downloads per month
Used in 2 crates

MIT license

175KB
3K SLoC

Rust 2.5K SLoC // 0.1% comments Go 441 SLoC // 0.2% comments Python 244 SLoC // 0.2% comments JavaScript 80 SLoC // 0.0% comments Shell 25 SLoC // 0.1% comments

Isahc (formerly cHTTP)

The practical HTTP client that is fun to use.

Note: cHTTP has been renamed to Isahc. Check out the latest and greatest versions under the new name!

Crates.io Documentation License

Key features

  • Full support for HTTP/1.1 and HTTP/2.
  • Configurable request timeouts.
  • Fully asynchronous core, with asynchronous and incremental reading and writing of request and response bodies.
  • Offers an ergonomic synchronous API as well as an asynchronous API with support for async/await.
  • Optional automatic redirect following.
  • Sessions and cookie persistence.
  • Request cancellation on drop.
  • Tweakable redirect policy.
  • Network socket configuration.
  • Uses the http crate as an interface for requests and responses.

Why cHTTP and not X?

cHTTP provides an easy-to-use, flexible, and idiomatic Rust API that makes sending HTTP requests a breeze. The goal of cHTTP is to make the easy way also provide excellent performance and correctness for common use cases.

cHTTP uses libcurl under the hood to handle the HTTP protocol and networking. Using curl as an engine for an HTTP client is a great choice for a few reasons:

  • It is a stable, actively developed, and very popular library.
  • It is well-supported on a diverse list of platforms.
  • The HTTP protocol has a lot of unexpected gotchas across different servers, and curl has been around the block long enough to handle many of them.
  • It is well optimized and offers the ability to implement asynchronous requests.

Safe Rust bindings to libcurl are provided by the curl crate, which you can use yourself if you want to use curl directly. cHTTP delivers a lot of value on top of vanilla curl, by offering a simpler, more idiomatic API and doing the hard work of turning the powerful multi interface into a futures-based API.

Installation

Install via Cargo by adding to your Cargo.toml file:

[dependencies]
chttp = "0.5"

Supported Rust versions

The current release is only guaranteed to work with the latest stable Rust compiler. When cHTTP reaches version 1.0, a more conservative policy will be adopted.

Feature flags

cHTTP is designed to be as "pay-as-you-need" as possible using Cargo feature flags and optional dependencies. Unstable features are also initially released behind feature flags until they are stabilized. You can add the feature names below to your Cargo.toml file to enable them:

[dependencies.chttp]
version = "0.5"
features = ["psl"]

Below is a list of all available feature flags and their meanings.

  • cookies: Enable persistent HTTP cookie support. Enabled by default.
  • http2: Enable HTTP/2 support in libcurl via libnghttp2. Enabled by default.
  • json: Additional serialization and deserialization of JSON bodies via serde. Disabled by default.
  • psl: Enable use of the Public Suffix List to filter out potentially malicious cross-domain cookies. Disabled by default.
  • static-curl: Use a bundled libcurl version and statically link to it. Enabled by default.
  • middleware-api: Enable the new middleware API. Unstable until the API is finalized. This an unstable feature whose interface may change between patch releases.

Documentation

Please check out the documentation for details on what cHTTP can do and how to use it.

To get you started, here is a really simple example that spits out the response body from https://example.org:

// Send a GET request and wait for the response.
let mut response = chttp::get("https://example.org")?
// Read the response body into a string and print it to standard output.
let body = response.body_mut().text()?;
println!("{}", body);

License

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

Dependencies

~13–23MB
~367K SLoC