Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Build
run: cargo build --verbose
- name: Build with Rusttls
run: cargo build --verbose --no-default-features --features rust-tls
- name: Run tests
run: cargo test --verbose
- uses: actions/checkout@v1
- name: Build
run: cargo build --verbose
- name: Build with Rusttls
run: cargo build --verbose --no-default-features --features rust-tls
- name: Run tests
run: cargo test --verbose
- name: Run tests with rust-tls
run: cargo test --verbose --no-default-features --features rust-tls
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributing
Code and documentation PRs are always welcome. Just remember to list out introduced changes.
Code contributions and documentation improvements are always welcome! Please include a clear description of the changes introduced in your pull requests.

If you want to suggest some improvements, report a bug, discuss a functionality, etc., feel free to open an issue.
For suggestions, bug reports, or feature requests, please open an issue.
54 changes: 27 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "http_req"
version = "0.13.3"
version = "0.14.0"
license = "MIT"
description = "simple and lightweight HTTP client with built-in HTTPS support"
repository = "https://github.com/jayjamesjay/http_req"
Expand All @@ -12,8 +12,8 @@ edition = "2021"

[dependencies]
unicase = "^2.8"
base64 = "^0.22.1"
zeroize = { version = "^1.8.1", features = ["zeroize_derive"] }
base64 = { version = "^0.22.1", optional = true }
zeroize = { version = "^1.8.1", features = ["zeroize_derive"], optional = true }
native-tls = { version = "^0.2", optional = true }
rustls = { version = "^0.23", optional = true }
rustls-pemfile = { version = "^2.2", optional = true }
Expand All @@ -22,11 +22,13 @@ webpki = { version = "^0.22", optional = true }
webpki-roots = { version = "^0.26", optional = true }

[features]
default = ["native-tls"]
default = ["native-tls", "auth"]
rust-tls = [
"rustls",
"rustls-pki-types",
"webpki",
"webpki-roots",
"rustls-pemfile",
"auth",
]
auth = ["base64", "zeroize"]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018-2024 jayjamesjay
Copyright (c) 2018-2025 jayjamesjay

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
71 changes: 47 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
# http_req

[![Rust](https://github.com/jayjamesjay/http_req/actions/workflows/rust.yml/badge.svg)](https://github.com/jayjamesjay/http_req/actions/workflows/rust.yml)
[![Crates.io](https://img.shields.io/badge/crates.io-v0.13.3-orange.svg?longCache=true)](https://crates.io/crates/http_req)
[![Docs.rs](https://docs.rs/http_req/badge.svg)](https://docs.rs/http_req/0.13.3/http_req/)
[![Crates.io](https://img.shields.io/badge/crates.io-v0.14.0-orange.svg?longCache=true)](https://crates.io/crates/http_req)
[![Docs.rs](https://docs.rs/http_req/badge.svg)](https://docs.rs/http_req/0.14.0/http_req/)

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

- HTTP and HTTPS via [rust-native-tls](https://github.com/sfackler/rust-native-tls) (or optionally [rus-tls](https://crates.io/crates/rustls))
- HTTP and HTTPS via [rust-native-tls](https://crates.io/crates/native-tls) (or optionally [rustls](https://crates.io/crates/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](https://github.com/sfackler/rust-native-tls),
http_req by default uses [rust-native-tls](https://crates.io/crates/native-tls),
which relies on TLS framework provided by OS on Windows and macOS, and OpenSSL
on all other platforms. But it also supports [rus-tls](https://crates.io/crates/rustls).

## Example

Basic HTTP GET request

```rust
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](https://github.com/jayjamesjay/http_req/tree/master/examples)
on all other platforms. But it also supports [rustls](https://crates.io/crates/rustls).

## All functionalities

- Support for both HTTP and HTTPS protocols via [rust-native-tls](https://crates.io/crates/native-tls) (or optionally [rustls](https://crates.io/crates/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 `Uri`s and partial support for relative `Uri`s
- 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

Expand All @@ -41,7 +38,7 @@ In order to use `http_req` with default configuration, add the following lines t

```toml
[dependencies]
http_req = "^0.13"
http_req = "^0.14"
```

### Rustls
Expand All @@ -50,9 +47,35 @@ In order to use `http_req` with `rustls` in your project, add the following line

```toml
[dependencies]
http_req = { version="^0.13", default-features = false, features = ["rust-tls"] }
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`:

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

## Example

Basic HTTP GET request

```rust
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](https://github.com/jayjamesjay/http_req/tree/master/examples)

## License

Licensed under [MIT](https://github.com/jayjamesjay/http_req/blob/master/LICENSE).
2 changes: 1 addition & 1 deletion examples/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn main() {
// Container for body of a response.
let mut body = Vec::new();
// URL of the website.
let uri = Uri::try_from("http://httpbin.org/basic-auth/foo/bar").unwrap();
let uri = Uri::try_from("https://httpbin.org/basic-auth/foo/bar").unwrap();
// Authentication details: username and password.
let auth = Authentication::basic("foo", "bar");

Expand Down
Loading