Crates.io | reqwest-traits |
lib.rs | reqwest-traits |
version | 0.2.0 |
source | src |
created_at | 2023-06-22 12:42:00.817982 |
updated_at | 2023-06-22 13:34:03.897176 |
description | Traits for reqwest to allow injecting a custom http client like reqwest_middleware::ClientWithMiddleware |
homepage | |
repository | https://github.com/ernesto-jimenez/reqwest-traits |
max_upload_size | |
id | 897295 |
size | 16,829 |
This crate provides traits for the reqwest crate. It is intended to be used by libraries that need to make HTTP requests, want to allow users to inject their own reqwest client, but don't want to force users to use reqwest::Client.
use reqwest_traits::Client;
struct MyClient<C: Client> {
http: C,
}
async fn plain_reqwest() {
let http = reqwest::Client::new();
let client = MyClient { http };
let req = client.http.get("https://example.com");
let response = req.send().await.unwrap();
assert_eq!(response.status(), 200);
}
async fn reqwest_middleware() {
let http = reqwest_middleware::ClientBuilder::new(
reqwest::Client::new(),
).build();
let client = MyClient { http };
let req = client.http.get("https://example.com");
let response = req.send().await.unwrap();
assert_eq!(response.status(), 200);
}
License: MIT