ergoreq
A human-centric web request client developed based on Reqwest.
- Friendly Url building
- Automatically retry support
- Middleware support
- Automatically manage cookies per-request (instead of per-client)
- Automatically redirect management per-request
- Supports all features of
reqwest
tracing support
- Well tested
Example
use ergoreq::{ErgoClient, ErgoCookieContainer, StringUrlBuilderTrait, ErgoStringToRequestExt};
use reqwest::redirect::Policy;
use std::sync::Arc;
use std::time::Duration;
#[tokio::main]
async fn main() {
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.user_agent("ergoreq/1.0")
.redirect(Policy::none()) .build()
.unwrap();
let client = ErgoClient::new(client).with_auto_redirect_count(5);
let cookie_store = Arc::new(ErgoCookieContainer::new_secure());
"https://httpbin.org"
.add_url_segment("cookies")
.add_url_segment("set")
.add_url_segment("test_cookie")
.add_url_segment("test_success")
.http_get(&client)
.with_cookie_store_ref(&cookie_store)
.send()
.await
.unwrap();
"https://httpbin.org"
.add_url_segments(&["cookies", "set", "test_cookie_1", "test_success_1"])
.http_get(&client)
.with_cookie_store_ref(&cookie_store)
.send()
.await
.unwrap();
client
.get("https://httpbin.org/cookies/set/test_cookie_1/test_success_1")
.with_cookie_store_ref(&cookie_store)
.send()
.await
.unwrap();
println!("Cookies: {:#?}", cookie_store.serialize_cookies());
let response = client
.get("https://httpbin.org/redirect/4") .send()
.await
.unwrap();
println!(
"Redirect {}",
if response.status().is_success() {
"success"
} else {
"fail"
}
)
}
More examples can be found in examples directory.
Requirement
The tested reqwest version is 0.12. Using reqwest older than 0.12 may cause compile error.
License
MIT
Thanks to