3个不稳定版本
| 0.2.0 | 2024年6月14日 | 
|---|---|
| 0.1.1 | 2023年10月29日 | 
| 0.1.0 | 2023年10月28日 | 
在 HTTP客户端 中排名第131
56KB
 1K  SLoC
ergoreq
基于Reqwest开发的人性化Web请求客户端。
- 支持自动重试
- 支持中间件
- 按请求自动管理cookie(而不是按客户端)
- 按请求自动管理重定向
- 支持reqwest的所有功能
- 支持tracing
- 经过良好测试
示例
    #[tokio::main]
    async fn main(){
        // Create a reqwest client first
        let client = reqwest::Client::builder()
            .timeout(Duration::from_secs(30))
            .user_agent("ergoreq/1.0")
            .redirect(Policy::none()) // remember to disable the redirect!
            .build()
            .unwrap();
        // Then create the ergo client
        let client = ErgoClient::new(client).with_auto_redirect_count(5); // global auto redirect count
        // Creates cookie store. You can impl a `CookieContainer` by your own.
        let cookie_store = Arc::new(ErgoCookieContainer::new(false, false, false));
        // Each request will automatically set and store cookie.
        client
            .get("https://httpbin.org/cookies/set/test_cookie/test_success")
            .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") // last time it will redirect to /get, so 4 represents 5 redirect times
            .send()
            .await
            .unwrap();
    
        println!(
            "Redirect {}",
            if response.status().is_success() {
                "success"
            } else {
                "fail"
            }
        )
    }
更多示例可以在示例目录中找到。
需求
测试的reqwest版本是0.12。使用0.12之前的reqwest可能会引起编译错误。
许可证
MIT
感谢
依赖项
~7–19MB
~281K SLoC