39 releases (25 breaking)

0.28.0 Mar 22, 2024
0.26.1 Aug 24, 2023
0.26.0 Jul 29, 2023
0.24.1 Feb 1, 2023
0.4.1 Mar 23, 2019

#18 in HTTP client

Download history 107436/week @ 2024-08-02 125117/week @ 2024-08-09 102258/week @ 2024-08-16 103590/week @ 2024-08-23 117197/week @ 2024-08-30 116341/week @ 2024-09-06 106826/week @ 2024-09-13 115292/week @ 2024-09-20 106386/week @ 2024-09-27 116964/week @ 2024-10-04 111966/week @ 2024-10-11 117342/week @ 2024-10-18 115464/week @ 2024-10-25 112533/week @ 2024-11-01 110155/week @ 2024-11-08 111059/week @ 2024-11-15

472,113 downloads per month
Used in 401 crates (74 directly)

MPL-2.0 license

160KB
3.5K SLoC

attohttpc

Documentation | Crates.io | Repository

Why attohttpc?

This project's goal is to provide a lightweight and simple HTTP client for the Rust ecosystem. The intended use is for projects that have HTTP needs where performance is not critical or when HTTP is not the main purpose of the application. Note that the project still tries to perform well and avoid allocation where possible, but stays away from Rust's asynchronous stack to provide a crate that's as small as possible. Features are provided behind feature flags when possible to allow users to get just what they need. Here are the goals of the project:

  • Lightweight
  • Secure
  • Easy to use
  • Modular
  • HTTP/1.1
  • Use quality crates from the ecosystem (http, url, encoding_rs), not reinventing the wheel.

Features

  • basic-auth support for basic auth
  • charsets support for decoding more text encodings than just UTF-8
  • compress support for decompressing response bodies using miniz_oxide (default)
  • compress-zlib support for decompressing response bodies using zlib instead of miniz_oxide (see flate2 backends)
  • compress-zlib-ng support for decompressing response bodies using zlib-ng instead of miniz_oxide (see flate2 backends)
  • json support for serialization and deserialization
  • form support for url encoded forms (does not include support for multipart)
  • multipart-form support for multipart forms (does not include support for url encoding)
  • tls-native support for tls connections using the native-tls crate (default)
  • tls-native-vendored activate the vendored feature of native-tls
  • tls-rustls-webpki-roots support for TLS connections using rustls instead of native-tls with Web PKI roots
  • tls-rustls-native-roots support for TLS connections using rustls with root certificates loaded from the rustls-native-certs crate

Usage

See the examples/ folder in the repository for more use cases.

let resp = attohttpc::post("https://my-api.com/do/something").json(&request)?.send()?;
if resp.is_success() {
    let response = resp.json()?;
    // ...
}

Current feature set

  • Query parameters, Request headers, Bodies, etc.
  • TLS, adding trusted certificates, disabling verification, etc. for both native-tls and rustls
  • Automatic redirection
  • Streaming response body
  • Multiple text encodings
  • Automatic compression/decompression with gzip or deflate
  • Transfer-Encoding: chunked
  • serde/json support
  • HTTP Proxies & HTTP_PROXY, HTTPS_PROXY, NO_PROXY environment variables.
  • Happy Eyeballs
  • Authentication (partial support)

License

This project is licensed under the MPL-2.0.

Dependencies

~3–16MB
~247K SLoC