# httpclient **Repository Path**: yak3/httpclient ## Basic Information - **Project Name**: httpclient - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-10-29 - **Last Updated**: 2025-11-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Alai HTTP Client 一个轻量级、灵活的 HTTP 客户端库,支持多种认证方式和请求配置。 ## 功能特性 - **多种认证方式**:支持 Basic Auth、Bearer Token 和 API Key。 - **灵活的请求配置**:可自定义 Headers、Query 参数和请求体。 - **简洁的 API 设计**:易于集成和使用。 ## 安装 使用以下命令安装库: ```bash go get github.com/yourusername/alai ``` ## 快速开始 以下是一个简单的示例,展示如何使用 `Fetch` 方法发送 HTTP 请求: ```go package main import ( "bytes" "fmt" "github.com/yourusername/alai/httpclient" ) func main() { // 初始化客户端 client := httpclient.NewClient("https://api.example.com") // 配置请求选项 options := httpclient.RequestOptions{ Method: "POST", Headers: map[string]string{"Content-Type": "application/json"}, AuthMethod: httpclient.BasicAuth{Username: "user", Password: "pass"}, Body: bytes.NewReader([]byte(`{"key": "value"}`)), } // 发送请求 resp, err := client.Fetch("users", options) if err != nil { fmt.Println("请求失败:", err) return } defer resp.Body.Close() fmt.Println("请求成功!") } ``` ## 认证方式 ### Basic Auth ```go auth := httpclient.BasicAuth{Username: "user", Password: "pass"} options.AuthMethod = auth ``` ### Bearer Token ```go auth := httpclient.BearerToken{Token: "your-token"} options.AuthMethod = auth ``` ### API Key ```go auth := httpclient.APIKeyAuth{Key: "your-api-key", Place: "header", Name: "X-API-Key"} options.AuthMethod = auth ``` ## 贡献 欢迎提交 Issue 或 Pull Request! ## 许可证 MIT