Skip to content

Commit

Permalink
Release v0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AurevoirXavier committed Nov 15, 2024
1 parent 555cc09 commit a2219e5
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 526 deletions.
24 changes: 23 additions & 1 deletion Cargo.lock

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

52 changes: 28 additions & 24 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "GPL-3.0"
name = "reqwew"
readme = "README.md"
repository = "https://github.com/hack-ink/reqwew"
version = "0.5.0"
version = "0.6.0"

[profile.ci-dev]
incremental = false
Expand All @@ -20,34 +20,37 @@ default = [
"charset",
"default-tls",
"http2",
"reqwest",
]

blocking = ["reqwest/blocking"]
brotli = ["reqwest/brotli"]
charset = ["reqwest/charset"]
cookies = ["reqwest/cookies"]
default-tls = ["reqwest/default-tls"]
deflate = ["reqwest/deflate"]
gzip = ["reqwest/gzip"]
hickory-dns = ["reqwest/hickory-dns"]
http2 = ["reqwest/http2"]
json = ["reqwest/json"]
multipart = ["reqwest/multipart"]
native-tls = ["reqwest/native-tls"]
native-tls-alpn = ["reqwest/native-tls-alpn"]
native-tls-vendored = ["reqwest/native-tls-vendored"]
rustls-tls = ["reqwest/rustls-tls"]
rustls-tls-manual-roots = ["reqwest/rustls-tls-manual-roots"]
rustls-tls-native-roots = ["reqwest/rustls-tls-native-roots"]
rustls-tls-webpki-roots = ["reqwest/rustls-tls-webpki-roots"]
socks = ["reqwest/socks"]
stream = ["reqwest/stream"]
zstd = ["reqwest/zstd"]
blocking = ["reqwest?/blocking"]
brotli = ["reqwest?/brotli"]
charset = ["reqwest?/charset"]
cookies = ["reqwest?/cookies"]
default-tls = ["reqwest?/default-tls"]
deflate = ["reqwest?/deflate"]
gzip = ["reqwest?/gzip"]
hickory-dns = ["reqwest?/hickory-dns"]
http2 = ["reqwest?/http2"]
json = ["reqwest?/json"]
multipart = ["reqwest?/multipart"]
native-tls = ["reqwest?/native-tls"]
native-tls-alpn = ["reqwest?/native-tls-alpn"]
native-tls-vendored = ["reqwest?/native-tls-vendored"]
rustls-tls = ["reqwest?/rustls-tls"]
rustls-tls-manual-roots = ["reqwest?/rustls-tls-manual-roots"]
rustls-tls-native-roots = ["reqwest?/rustls-tls-native-roots"]
rustls-tls-webpki-roots = ["reqwest?/rustls-tls-webpki-roots"]
socks = ["reqwest?/socks"]
stream = ["reqwest?/stream"]
zstd = ["reqwest?/zstd"]

extra-tracing = ["reqwest"]

[dependencies]
# crates.io
bytes = { version = "1.8" }
reqwest = { version = "0.12", default-features = false }
reqwest = { version = "0.12", optional = true, default-features = false }
serde = { version = "1.0" }
serde_json = { version = "1.0" }
thiserror = { version = "2.0" }
Expand All @@ -56,4 +59,5 @@ tracing = { version = "0.1" }

[dev-dependencies]
# crates.io
tokio = { version = "1.41", features = ["macros"] }
reqwest = { version = "0.12", features = ["blocking"] }
tokio = { version = "1.41", features = ["macros"] }
47 changes: 40 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<div align="center">

# reqwew
### Reqwest effortless wrapper.
### HTTP client effortless wrapper.

[![License](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![Checks](https://github.com/hack-ink/reqwew/actions/workflows/checks.yml/badge.svg?branch=main)](https://github.com/hack-ink/reqwew/actions/workflows/checks.yml)
[![Release](https://github.com/hack-ink/reqwew/actions/workflows/release.yml/badge.svg)](https://github.com/hack-ink/reqwew/actions/workflows/release.yml)
[![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/hack-ink/reqwew)](https://github.com/hack-ink/reqwew/tags)
[![GitHub code lines](https://tokei.rs/b1/github/hack-ink/reqwew)](https://github.com/hack-ink/reqwew)
[![GitHub last commit](https://img.shields.io/github/last-commit/hack-ink/reqwew?color=red&style=plastic)](https://github.com/hack-ink/reqwew)
</div>

At the beginning, the goal was to create an easy-to-use wrapper for [reqwest](https://github.com/seanmonstar/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.
</div>

## Usage
### Async
Expand All @@ -25,12 +28,26 @@ use serde_json::Value;
pub static CLIENT: LazyLock<Client> = reqwew::lazy(|| Client::default());

// Async.
let resp = CLIENT.get_with_retries("https://httpbin.org/get", 3, 50).await.unwrap();
let resp = CLIENT
.request_with_retries(
CLIENT.request(Method::GET, "https://httpbin.org/get").build().unwrap(),
3,
50,
)
.await
.unwrap();

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

let resp = CLIENT.post_with_retries("https://httpbin.org/post", "hello", 3, 50).await.unwrap();
let resp = CLIENT
.request_with_retries(
CLIENT.request(Method::POST, "https://httpbin.org/post").body("hello").build().unwrap(),
3,
50,
)
.await
.unwrap();

assert!(resp.clone().text().contains("https://httpbin.org/post"));
assert_eq!(resp.json::<Value>().unwrap()["url"].as_str().unwrap(), "https://httpbin.org/post");
Expand All @@ -42,20 +59,36 @@ assert_eq!(resp.json::<Value>().unwrap()["url"].as_str().unwrap(), "https://http
use std::sync::LazyLock;
// crates.io
use reqwew::{
blocking::Http as BlockingHttp, reqwest::blocking::Client as BlockingClient, Response,
blocking::Http as BlockingHttp, reqwest::blocking::Client as BlockingClient, Response,
};
use serde_json::Value;

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

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

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

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

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

0 comments on commit a2219e5

Please sign in to comment.