attohttpc
attohttpc copied to clipboard
Rust lightweight HTTP 1.1 client
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-authsupport for basic authcharsetssupport for decoding more text encodings than just UTF-8compresssupport for decompressing response bodies usingminiz_oxide(default)compress-zlibsupport for decompressing response bodies usingzlibinstead ofminiz_oxide(see flate2 backends)compress-zlib-ngsupport for decompressing response bodies usingzlib-nginstead ofminiz_oxide(see flate2 backends)jsonsupport for serialization and deserializationformsupport for url encoded forms (does not include support for multipart)multipart-formsupport for multipart forms (does not include support for url encoding)tlssupport for tls connections (default)tls-vendoredactivate thevendoredfeature ofnative-tlscraterustlsortls-rustlssupport for TLS connections usingrustlsinstead ofnative-tls
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-tlsandrustls - 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_PROXYenvironment variables. - Happy Eyeballs
- Authentication (partial support)
License
This project is licensed under the MPL-2.0.