#http-request #request #http #http-req

http_req

simple and lightweight HTTP client with built-in HTTPS support

48 releases

new 0.14.0 May 5, 2025
0.13.2 Mar 30, 2025
0.13.1 Dec 6, 2024
0.13.0 Oct 14, 2024
0.3.1 Nov 21, 2018

#29 in HTTP client

Download history 1483/week @ 2025-01-15 1266/week @ 2025-01-22 1280/week @ 2025-01-29 2498/week @ 2025-02-05 1665/week @ 2025-02-12 1617/week @ 2025-02-19 1439/week @ 2025-02-26 1994/week @ 2025-03-05 1588/week @ 2025-03-12 1930/week @ 2025-03-19 1730/week @ 2025-03-26 1544/week @ 2025-04-02 1846/week @ 2025-04-09 1704/week @ 2025-04-16 2391/week @ 2025-04-23 2729/week @ 2025-04-30

8,929 downloads per month
Used in 52 crates (27 directly)

MIT license

145KB
3K SLoC

http_req

Rust Crates.io Docs.rs

Simple and lightweight HTTP client with built-in HTTPS support.

  • HTTP and HTTPS via rust-native-tls (or optionally rustls)
  • Small binary size (0.7 MB for a basic GET request in the default configuratio)
  • Minimal number of dependencies

Requirements

http_req by default uses rust-native-tls, which relies on TLS framework provided by OS on Windows and macOS, and OpenSSL on all other platforms. But it also supports rustls.

All functionalities

  • Support for both HTTP and HTTPS protocols via rust-native-tls (or optionally rustls)
  • Creating and sending HTTP requests using the Request type (with extended capabilities provided via RequestMessage and Stream)
  • Representing HTTP responses with the Response type, allowing easy access to details like the status code and headers
  • Handling redirects using the RedirectPolicy
  • Support for Basic and Bearer authentication
  • Processing responses with Transfer-Encoding: chunked
  • Managing absolute Uris and partial support for relative Uris
  • Enforcing timeouts on requests
  • Downloading data in a streaming fashion, allowing direct saving to disk (minimizing RAM usage)
  • Error handling system allowing for better debugging
  • Utility functions for easily sending common request types: get, head, post

Usage

Default configuration

In order to use http_req with default configuration, add the following lines to Cargo.toml:

[dependencies]
http_req = "^0.14"

Rustls

In order to use http_req with rustls in your project, add the following lines to Cargo.toml:

[dependencies]
http_req = { version="^0.14", default-features = false, features = ["rust-tls"] }

HTTP only

In order to use http_req without any additional features in your project (no HTTPS, no Authentication), add the following lines to Cargo.toml:

[dependencies]
http_req = { version="^0.14", default-features = false }

Example

Basic HTTP GET request

use http_req::request;

fn main() {
    let mut body = Vec::new(); //Container for body of a response.
    let res = request::get("https://doc.rust-lang.org/", &mut body).unwrap();

    println!("Status: {} {}", res.status_code(), res.reason());
}

Take a look at more examples

License

Licensed under MIT.

Dependencies

~0.2–11MB
~144K SLoC