{"id":21909058,"url":"https://github.com/rezmoss/axios4go","last_synced_at":"2025-04-16T01:54:45.599Z","repository":{"id":255438720,"uuid":"850328916","full_name":"rezmoss/axios4go","owner":"rezmoss","description":"A Go HTTP client library inspired by Axios, providing a simple and intuitive API for making HTTP requests with features like interceptors, JSON handling, configurable instances, and automatic retries","archived":false,"fork":false,"pushed_at":"2025-01-22T00:13:34.000Z","size":120,"stargazers_count":23,"open_issues_count":3,"forks_count":9,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-16T01:54:30.350Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rezmoss.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-31T13:24:08.000Z","updated_at":"2025-03-26T08:34:51.000Z","dependencies_parsed_at":"2024-09-17T01:51:45.712Z","dependency_job_id":"7b941987-4af1-4efe-aa7f-ce7111294e07","html_url":"https://github.com/rezmoss/axios4go","commit_stats":null,"previous_names":["rezmoss/axios4go"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rezmoss%2Faxios4go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rezmoss%2Faxios4go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rezmoss%2Faxios4go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rezmoss%2Faxios4go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rezmoss","download_url":"https://codeload.github.com/rezmoss/axios4go/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249183107,"owners_count":21226141,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-28T17:15:03.881Z","updated_at":"2025-04-16T01:54:45.592Z","avatar_url":"https://github.com/rezmoss.png","language":"Go","funding_links":[],"categories":["Networking","网络"],"sub_categories":["HTTP Clients","HTTP客户端"],"readme":"# axios4go\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/rezmoss/axios4go.svg)](https://pkg.go.dev/github.com/rezmoss/axios4go)\n[![Go Report Card](https://goreportcard.com/badge/github.com/rezmoss/axios4go)](https://goreportcard.com/report/github.com/rezmoss/axios4go)\n[![Release](https://img.shields.io/github/v/release/rezmoss/axios4go.svg?style=flat-square)](https://github.com/rezmoss/axios4go/releases)\n[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/9401/badge)](https://www.bestpractices.dev/projects/9401)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\naxios4go is a Go HTTP client library inspired by [Axios](https://github.com/axios/axios) (a promise based HTTP client for node.js), providing a simple and intuitive API for making HTTP requests. It offers features like JSON handling, configurable instances, and support for various HTTP methods.\n\n## Table of Contents\n\n- [Features](#features)\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Making a Simple Request](#making-a-simple-request)\n  - [Using Request Options](#using-request-options)\n  - [Making POST Requests](#making-post-requests)\n  - [Using Async Requests](#using-async-requests)\n  - [Creating a Custom Client](#creating-a-custom-client)\n  - [Using Interceptors](#using-interceptors)\n  - [Handling Progress](#handling-progress)\n  - [Using Proxy](#using-proxy)\n- [Configuration Options](#configuration-options)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Features\n\n- Simple and intuitive API\n- Support for `GET`, `POST`, `PUT`, `DELETE`, `HEAD`, `OPTIONS`, and `PATCH` methods\n- JSON request and response handling\n- Configurable client instances\n- Global and per-request timeout management\n- Redirect management\n- Basic authentication support\n- Customizable request options\n- Promise-like asynchronous requests\n- Request and response interceptors\n- Upload and download progress tracking\n- Proxy support\n- Configurable max content length and body length\n\n## Installation\n\nTo install `axios4go`, use `go get`:\n\n```bash\ngo get -u github.com/rezmoss/axios4go\n```\n\n**Note**: Requires Go 1.13 or later.\n\n## Usage\n\n### Making a Simple Request\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n\n    \"github.com/rezmoss/axios4go\"\n)\n\nfunc main() {\n    resp, err := axios4go.Get(\"https://api.example.com/data\")\n    if err != nil {\n        fmt.Printf(\"Error: %v\\n\", err)\n        return\n    }\n    fmt.Printf(\"Status Code: %d\\n\", resp.StatusCode)\n    fmt.Printf(\"Body: %s\\n\", string(resp.Body))\n}\n```\n\n### Using Request Options\n\n```go\nresp, err := axios4go.Get(\"https://api.example.com/data\", \u0026axios4go.RequestOptions{\n    Headers: map[string]string{\n        \"Authorization\": \"Bearer token\",\n    },\n    Params: map[string]string{\n        \"query\": \"golang\",\n    },\n})\n```\n\n### Making POST Requests\n\n```go\nbody := map[string]interface{}{\n    \"name\": \"John Doe\",\n    \"age\":  30,\n}\nresp, err := axios4go.Post(\"https://api.example.com/users\", body)\nif err != nil {\n    fmt.Printf(\"Error: %v\\n\", err)\n    return\n}\nfmt.Printf(\"Status Code: %d\\n\", resp.StatusCode)\nfmt.Printf(\"Body: %s\\n\", string(resp.Body))\n```\n\n### Using Async Requests\n\n```go\naxios4go.GetAsync(\"https://api.example.com/data\").\n    Then(func(response *axios4go.Response) {\n        fmt.Printf(\"Status Code: %d\\n\", response.StatusCode)\n        fmt.Printf(\"Body: %s\\n\", string(response.Body))\n    }).\n    Catch(func(err error) {\n        fmt.Printf(\"Error: %v\\n\", err)\n    }).\n    Finally(func() {\n        fmt.Println(\"Request completed\")\n    })\n```\n\n### Creating a Custom Client\n\n```go\nclient := axios4go.NewClient(\"https://api.example.com\")\n\nresp, err := client.Request(\u0026axios4go.RequestOptions{\n    Method: \"GET\",\n    URL:    \"/users\",\n    Headers: map[string]string{\n        \"Authorization\": \"Bearer token\",\n    },\n})\nif err != nil {\n    fmt.Printf(\"Error: %v\\n\", err)\n    return\n}\nfmt.Printf(\"Status Code: %d\\n\", resp.StatusCode)\nfmt.Printf(\"Body: %s\\n\", string(resp.Body))\n```\n\n### Using Interceptors\n\n```go\noptions := \u0026axios4go.RequestOptions{\n    InterceptorOptions: axios4go.InterceptorOptions{\n        RequestInterceptors: []func(*http.Request) error{\n            func(req *http.Request) error {\n                req.Header.Set(\"X-Custom-Header\", \"value\")\n                return nil\n            },\n        },\n        ResponseInterceptors: []func(*http.Response) error{\n            func(resp *http.Response) error {\n                fmt.Printf(\"Response received with status: %d\\n\", resp.StatusCode)\n                return nil\n            },\n        },\n    },\n}\n\nresp, err := axios4go.Get(\"https://api.example.com/data\", options)\n```\n\n### Handling Progress\n\n```go\noptions := \u0026axios4go.RequestOptions{\n    OnUploadProgress: func(bytesRead, totalBytes int64) {\n        fmt.Printf(\"Upload progress: %d/%d bytes\\n\", bytesRead, totalBytes)\n    },\n    OnDownloadProgress: func(bytesRead, totalBytes int64) {\n        fmt.Printf(\"Download progress: %d/%d bytes\\n\", bytesRead, totalBytes)\n    },\n}\n\nresp, err := axios4go.Post(\"https://api.example.com/upload\", largeData, options)\n```\n\n### Using Proxy\n\n```go\noptions := \u0026axios4go.RequestOptions{\n    Proxy: \u0026axios4go.Proxy{\n        Protocol: \"http\",\n        Host:     \"proxy.example.com\",\n        Port:     8080,\n        Auth: \u0026axios4go.Auth{\n            Username: \"proxyuser\",\n            Password: \"proxypass\",\n        },\n    },\n}\n\nresp, err := axios4go.Get(\"https://api.example.com/data\", options)\n```\n\n## Configuration Options\n\n`axios4go` supports various configuration options through the `RequestOptions` struct:\n\n- **Method**: HTTP method (`GET`, `POST`, etc.)\n- **URL**: Request URL (relative to `BaseURL` if provided)\n- **BaseURL**: Base URL for the request (overrides client's `BaseURL` if set)\n- **Params**: URL query parameters (`map[string]string`)\n- **Body**: Request body (can be `string`, `[]byte`, or any JSON serializable object)\n- **Headers**: Custom headers (`map[string]string`)\n- **Timeout**: Request timeout in milliseconds\n- **Auth**: Basic authentication credentials (`\u0026Auth{Username: \"user\", Password: \"pass\"}`)\n- **ResponseType**: Expected response type (default is \"json\")\n- **ResponseEncoding**: Expected response encoding (default is \"utf8\")\n- **MaxRedirects**: Maximum number of redirects to follow\n- **MaxContentLength**: Maximum allowed response content length\n- **MaxBodyLength**: Maximum allowed request body length\n- **Decompress**: Whether to decompress the response body (default is true)\n- **ValidateStatus**: Function to validate HTTP response status codes\n- **InterceptorOptions**: Request and response interceptors\n- **Proxy**: Proxy configuration\n- **OnUploadProgress**: Function to track upload progress\n- **OnDownloadProgress**: Function to track download progress\n\n**Example**:\n\n```go\noptions := \u0026axios4go.RequestOptions{\n    Method: \"POST\",\n    URL:    \"/submit\",\n    Headers: map[string]string{\n        \"Content-Type\": \"application/json\",\n    },\n    Body: map[string]interface{}{\n        \"title\":   \"Sample\",\n        \"content\": \"This is a sample post.\",\n    },\n    Auth: \u0026axios4go.Auth{\n        Username: \"user\",\n        Password: \"pass\",\n    },\n    Params: map[string]string{\n        \"verbose\": \"true\",\n    },\n    Timeout:          5000, // 5 seconds\n    MaxRedirects:     5,\n    MaxContentLength: 1024 * 1024, // 1MB\n    ValidateStatus: func(statusCode int) bool {\n        return statusCode \u003e= 200 \u0026\u0026 statusCode \u003c 300\n    },\n}\n\nresp, err := client.Request(options)\n```\n\n## Contributing\n\nContributions to `axios4go` are welcome! Please follow these guidelines:\n\n- **Fork the repository** and create a new branch for your feature or bug fix.\n- **Ensure your code follows Go conventions** and passes all tests.\n- **Write tests** for new features or bug fixes.\n- **Submit a Pull Request** with a clear description of your changes.\n\n## License\n\nThis project is licensed under the Apache License, Version 2.0. See the [LICENSE](LICENSE) file for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frezmoss%2Faxios4go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frezmoss%2Faxios4go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frezmoss%2Faxios4go/lists"}