Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ernesto-jimenez/reqwest-traits
Traits for reqwest to allow injecting a custom http client like reqwest_middleware::ClientWithMiddleware
https://github.com/ernesto-jimenez/reqwest-traits
reqwest rust-lang
Last synced: 16 days ago
JSON representation
Traits for reqwest to allow injecting a custom http client like reqwest_middleware::ClientWithMiddleware
- Host: GitHub
- URL: https://github.com/ernesto-jimenez/reqwest-traits
- Owner: ernesto-jimenez
- License: mit
- Created: 2023-06-22T08:51:05.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-06-22T13:32:54.000Z (over 1 year ago)
- Last Synced: 2024-11-19T23:49:47.941Z (about 2 months ago)
- Topics: reqwest, rust-lang
- Language: Rust
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# reqwest-traits
## reqwest-traits
This crate provides traits for the [reqwest](https://crates.io/crates/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.### Example use cases
- Use reqwest::Client in your program, but inject client with
[rvcr](https://crates.io/crates/rvcr) for testing to avoid making real HTTP requests.
- Let users of your library inject their own reqwest::Client, if they want a caching or tracing
middleware, a reqwest_middleware::ClientWithMiddleware.### Example
```rust
use reqwest_traits::Client;struct MyClient {
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