unistore-http 0.1.0

HTTP client capability for UniStore
Documentation

unistore-http

UniStore HTTP 客户端能力,基于 reqwest 提供统一的 HTTP 请求接口。

概述

unistore-http 提供:

  • 流畅的请求构建器 API
  • 自动重试与超时控制
  • JSON/表单/多部分表单支持
  • 与 UniStore 生命周期集成

安装

[dependencies]

unistore-http = "0.1"

快速开始

use unistore_http::{HttpClient, HttpConfig};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // 创建客户端
    let client = HttpClient::new()?;
    
    // GET 请求
    let response = client.get("https://api.example.com/users")
        .header("Authorization", "Bearer token")
        .send()
        .await?;
    
    // POST JSON
    let user = serde_json::json!({"name": "Alice"});
    let response = client.post("https://api.example.com/users")
        .json(&user)
        .send()
        .await?;
    
    Ok(())
}

配置

let config = HttpConfig::builder()
    .timeout(Duration::from_secs(30))
    .max_retries(3)
    .user_agent("MyApp/1.0")
    .build();

let client = HttpClient::with_config(config)?;

底层访问

需要直接使用 reqwest 时:

let inner: &reqwest::Client = client.inner();

许可证

MIT OR Apache-2.0

致谢

本 crate 基于以下优秀项目构建:

  • reqwest by Sean McArthur - 强大的 HTTP 客户端库
  • tokio - 异步运行时

感谢这些项目的作者和贡献者们!