#http-request #request #http #utility #networking

tinyquest

A *tiny* library used for making HTTP requests. It interacts with native-tls to be as small as possible, so it can be used in small CLI's

5 releases (3 breaking)

0.4.1 Nov 27, 2020
0.4.0 Nov 16, 2020
0.3.0 Sep 28, 2020
0.2.0 Sep 25, 2020
0.1.0 Sep 12, 2020

#382 in HTTP client

MIT license

20KB
472 lines

Tinyquest

Tinyquest is a Rust library aiming to give you a high-level, yet performant experience. The binary size is minimal, to make small bundled CLI's which need to make requests plausible.

Usage

To use tinyquest, add this to your Cargo.toml:

[dependencies]
tinyquest = "0.4.1"

Then, add this to your crate:

use tinyquest::{get, write};

fn main() {
  // ...
}

Examples

Request a website, and print the HTML:

use tinyquest::get;

fn main() {
    match tinyquest::get("rust-lang.org", "my-application/0.1.0") {
        Err(err) => eprintln!("Failed: {:?}", err),
        Ok(mut result) => {
            match result.follow_redirects() {
                Ok(s) => {
                    let (parts, body) = s.into_parts();
                    println!(
                        "Headers: '{:#?}'\n\
                        Body: '{}'",
                        parts.headers,
                        String::from_utf8_lossy(&body),
                    );
                }
                Err(err) => eprintln!("Failed: {:#?}", err),
            };
        }
    };
}

License

This crate is licensed under the MIT license, and all contributions must also be.

Dependencies

~0.6–9MB
~89K SLoC