14 releases (5 breaking)

Uses new Rust 2024

new 0.7.0 Mar 15, 2025
0.6.1 Dec 22, 2024
0.6.0 Nov 15, 2024
0.2.3 Jul 14, 2024

#107 in HTTP client

Download history 4/week @ 2024-11-24 13/week @ 2024-12-01 47/week @ 2024-12-08 4/week @ 2024-12-15 246/week @ 2024-12-22 1/week @ 2024-12-29 9/week @ 2025-01-05 5/week @ 2025-01-12 75/week @ 2025-02-02 68/week @ 2025-02-09 15/week @ 2025-02-16 5/week @ 2025-02-23 63/week @ 2025-03-09

101 downloads per month
Used in 3 crates (2 directly)

GPL-3.0 license

34KB
205 lines

reqwew

HTTP client effortless wrapper

License Checks Release GitHub tag (latest by date) GitHub code lines GitHub last commit

At the beginning, the goal was to create an easy-to-use wrapper for reqwest.

Now it has evolved into a more generic solution, allowing you to implement the HTTP trait for any client to enjoy the handy features provided by reqwew.

Usage

Async

// std
use std::sync::LazyLock;
// crates.io
use reqwew::{
	reqwest::{Client, Method},
	Http, Response,
};
use serde_json::Value;

// Lazy static.
pub static CLIENT: LazyLock<Client> = reqwew::lazy(Client::default);

// Async.
let req = || async {
	CLIENT
		.request_with_retries(
			CLIENT.request(Method::GET, "https://httpbin.org/get").build().unwrap(),
			3,
			50,
		)
		.await
		.unwrap()
};

assert!(req().await.text().await.unwrap().contains("httpbin.org"));
assert_eq!(
	req().await.json::<Value>().await.unwrap()["headers"]["Host"].as_str().unwrap(),
	"httpbin.org"
);

let req = || async {
	CLIENT
		.request_with_retries(
			CLIENT.request(Method::POST, "https://httpbin.org/post").body("hello").build().unwrap(),
			3,
			50,
		)
		.await
		.unwrap()
};

assert!(req().await.text().await.unwrap().contains("https://httpbin.org/post"));
assert_eq!(
	req().await.json::<Value>().await.unwrap()["url"].as_str().unwrap(),
	"https://httpbin.org/post"
);

Blocking

// std
use std::sync::LazyLock;
// crates.io
use reqwew::{
	blocking::Http as BlockingHttp,
	reqwest::{blocking::Client as BlockingClient, Method},
	Response,
};
use serde_json::Value;

// Lazy static.
pub static BLOCKING_CLIENT: LazyLock<BlockingClient> = reqwew::lazy(BlockingClient::default);

// Blocking.
let req = || {
	BLOCKING_CLIENT
		.request_with_retries(
			BLOCKING_CLIENT.request(Method::GET, "https://httpbin.org/get").build().unwrap(),
			3,
			50,
		)
		.unwrap()
};

assert!(req().text().unwrap().contains("httpbin.org"));
assert_eq!(req().json::<Value>().unwrap()["headers"]["Host"].as_str().unwrap(), "httpbin.org");

let req = || {
	BLOCKING_CLIENT
		.request_with_retries(
			BLOCKING_CLIENT
				.request(Method::POST, "https://httpbin.org/post")
				.body("hello")
				.build()
				.unwrap(),
			3,
			50,
		)
		.unwrap()
};

assert!(req().text().unwrap().contains("https://httpbin.org/post"));
assert_eq!(req().json::<Value>().unwrap()["url"].as_str().unwrap(), "https://httpbin.org/post");

Dependencies

~6–24MB
~412K SLoC