{"id":23508976,"url":"https://github.com/maxbolgarin/cliex","last_synced_at":"2025-07-02T01:35:43.597Z","repository":{"id":267283046,"uuid":"893836952","full_name":"maxbolgarin/cliex","owner":"maxbolgarin","description":"Easy-to-use HTTP client with Circuit Breaker","archived":false,"fork":false,"pushed_at":"2024-12-10T18:05:24.000Z","size":58,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-13T15:57:03.991Z","etag":null,"topics":["api","go","golang","http","rest","rest-api","resty"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maxbolgarin.png","metadata":{"files":{"readme":"README.md","changelog":null,"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-11-25T09:49:13.000Z","updated_at":"2024-12-10T18:04:41.000Z","dependencies_parsed_at":"2025-02-16T19:45:18.294Z","dependency_job_id":null,"html_url":"https://github.com/maxbolgarin/cliex","commit_stats":null,"previous_names":["maxbolgarin/cliex"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/maxbolgarin/cliex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbolgarin%2Fcliex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbolgarin%2Fcliex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbolgarin%2Fcliex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbolgarin%2Fcliex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxbolgarin","download_url":"https://codeload.github.com/maxbolgarin/cliex/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbolgarin%2Fcliex/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263060998,"owners_count":23407596,"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":["api","go","golang","http","rest","rest-api","resty"],"created_at":"2024-12-25T11:36:15.484Z","updated_at":"2025-07-02T01:35:43.573Z","avatar_url":"https://github.com/maxbolgarin.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cliex\n\n[![Go Version][version-img]][doc] [![GoDoc][doc-img]][doc] [![Build][ci-img]][ci] [![GoReport][report-img]][report]\n\n\nThe **cliex** package is a robust and extensible HTTP client designed for making HTTP requests in Go applications, leveraging the capabilities of the `resty` library. It simplifies the process of sending HTTP requests and provides advanced features such as configuration options, circuit breaking, retries, and more.\n\nThis package is a wrapper on [resty](https://github.com/go-resty/resty) — it makes HTTP requests less verbose, adds request based retry settings and a circuit breaker.\n\n## Table of Contents\n\n1. [Introduction](#introduction)\n2. [Features](#features)\n3. [Installation](#installation)\n4. [Usage](#usage)\n   - [Initialization](#initialization)\n   - [Using HTTPSet for Multiple Clients](#using-httpset-for-multiple-clients)\n   - [Handling Broken Clients](#handling-broken-clients)\n5. [Configuration Options](#configuration-options)\n6. [Request Options](#request-options)\n7. [Contributing](#contributing)\n8. [License](#license)\n\n## Features\n\n- **Customizable HTTP Client:** Configure base URL, user agent, proxy, authentication tokens, and more.\n- **Circuit Breaker Support:** Protects your application from cascading failures by using circuit breakers for HTTP requests.\n- **Requests with Retries:** Automatically retries failed requests with exponential backoff.\n- **Logging Support:** Integrates with custom loggers for request and error logging.\n- **HTTP Client Sets:** Manage groups of HTTP clients, enabling requests to multiple endpoints with error handling for broken clients.\n- **Flexible Request Options:** Supports custom headers, query parameters, form data, body payloads, and more.\n- **SSL/TLS Configuration:** Allows configuration of CA files, client certificates, and insecure requests.\n- **Debug Mode:** Enables additional logging for request troubleshooting.\n\n## Installation\n\nTo install the package, use:\n\n```bash\ngo get -u github.com/maxbolgarin/cliex\n```\n\n## Usage\n\n### Initialization\n\nCreate an HTTP client using the provided configuration options.\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"log\"\n\t\"github.com/maxbolgarin/cliex\"\n)\n\nfunc main() {\n\t// Creating a new HTTP client with default settings\n\tclient := cliex.New(\n\t\tcliex.WithBaseURL(\"https://api.example.com\"),\n\t\tcliex.WithUserAgent(\"MyApp/1.0\"),\n\t\tcliex.WithAuthToken(\"Bearer YOUR_TOKEN\"),\n\t\tcliex.WithRequestTimeout(10*time.Second),\n\t\tcliex.WithDebug(true),\n\t)\n\n\t// Making a GET request\n\tresp, err := client.Get(context.Background(), \"/endpoint\")\n\tif err != nil {\n\t\tlog.Fatalf(\"Request failed: %v\", err)\n\t}\n\n\tlog.Printf(\"Response: %s\", resp.String())\n}\n```\n\n### Using HTTPSet for Multiple Clients\n\nCreate a set of HTTP clients and perform operations on them collectively.\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"log\"\n\t\"github.com/maxbolgarin/cliex\"\n)\n\nfunc main() {\n\tclientSet := cliex.NewSetFromConfigs(\n\t\tcliex.Config{BaseURL: \"https://service1.example.com\"},\n\t\tcliex.Config{BaseURL: \"https://service2.example.com\"},\n\t)\n\n\tresp, err := clientSet.Get(context.Background(), \"/shared-resource\")\n\tif err != nil {\n\t\tlog.Fatalf(\"Request failed: %v\", err)\n\t}\n\n\tfor _, r := range resp {\n\t\tlog.Printf(\"Response from client: %s\", r.String())\n\t}\n}\n```\n\n### Handling Broken Clients\n\nYou can manage failing clients within a set and choose to retry or handle them separately.\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"log\"\n\t\"github.com/maxbolgarin/cliex\"\n)\n\nfunc main() {\n\tclientSet, err := cliex.NewSetFromConfigs(\n\t\tcliex.Config{BaseURL: \"https://service1.example.com\"},\n\t\tcliex.Config{BaseURL: \"https://service2.example.com\"},\n\t)\n\tif err != nil {\n\t\tlog.Fatalf(\"Error creating client set: %v\", err)\n\t}\n\n\t_, err = clientSet.Get(context.Background(), \"/resource\")\n\tif err != nil {\n\t\tlog.Printf(\"Request failed: %v\", err)\n\t\tbrokenClients := clientSet.GetBroken()\n\n\t\t// Retry or handle broken clients\n\t\tfor _, index := range brokenClients {\n\t\t\tlog.Printf(\"Broken client index: %d\", index)\n\t\t}\n\t}\n}\n```\n\n## Configuration Options\n\n- `BaseURL`: Sets the base URL for HTTP requests.\n- `UserAgent`: Sets the User-Agent header for each request.\n- `AuthToken`: Provides an Authorization header with a bearer token.\n- `ProxyAddress`: Defines a proxy server for sending requests.\n- `RequestTimeout`: Configures the maximum amount of time to wait for a request.\n- `CAFiles`: Loads CA certificates for SSL validation.\n- `ClientCertFile`/`ClientKeyFile`: Client-side certificate and key for TLS.\n- `Insecure`: Allows insecure SSL connections.\n- `Debug`: Enables detailed logging.\n- `CircuitBreaker`: Activates the circuit breaker feature.\n\n## Request Options\n\n| Option                  | Description                                                                                              | Type                          |\n|-------------------------|----------------------------------------------------------------------------------------------------------|-------------------------------|\n| `Method`                | The HTTP method to use (e.g., GET, POST, PUT, DELETE).                                                   | `string`                      |\n| `Headers`               | A map of header keys and values to include in the request.                                               | `map[string]string`           |\n| `Query`                 | A map of query string parameters and their values.                                                       | `map[string]string`           |\n| `PathParams`            | Path parameters for the request URL (e.g., `/v1/users/{userId}`).                                        | `map[string]string`           |\n| `Cookies`               | Cookies to include in the request.                                                                       | `[]*http.Cookie`              |\n| `FormData`              | Form data to include when submitting a form.                                                             | `map[string]string`           |\n| `Files`                 | Files to upload, where the key is the file name and the value is the file path.                          | `map[string]string`           |\n| `AuthToken`             | Authentication token for the request.                                                                    | `string`                      |\n| `BasicAuthUser`         | Username for basic authentication.                                                                       | `string`                      |\n| `BasicAuthPass`         | Password for basic authentication.                                                                       | `string`                      |\n| `ForceContentType`      | Specifies a custom content type to parse the response (e.g., `application/json`).                         | `string`                      |\n| `Body`                  | The body of the request, can be any type.                                                                | `any`                         |\n| `Result`                | A variable to store the response body.                                                                   | `any`                         |\n| `OutputPath`            | File path to save the response output.                                                                   | `string`                      |\n| `RequestName`           | Name of the request for logging purposes.                                                                | `string`                      |\n| `RetryCount`            | Number of times to retry the request if it fails.                                                        | `int`                         |\n| `RetryWaitTime`         | Initial wait time between retries (default: 100 milliseconds).                                           | `time.Duration`               |\n| `RetryMaxWaitTime`      | Maximum wait time between retries (default: 2 seconds).                                                  | `time.Duration`               |\n| `InfiniteRetry`         | Whether to retry the request indefinitely.                                                               | `bool`                        |\n| `RetryOnlyServerErrors` | Whether to retry only for server (5xx) errors.                                                           | `bool`                        |\n| `NoLogRetryError`       | Whether to suppress logging of retry errors.                                                             | `bool`                        |\n| `EnableTrace`           | Enable tracing of the request, accessible via `resp.Request.TraceInfo()`.                                | `bool`                        |\n\n\n## Contributing\n\nContributions to improve the package are welcome. Please ensure any changes come with tests, and are validated against existing integrations. \n\n## License\n\nThis project is licensed under the terms of the [MIT License](LICENSE).\n\n[MIT License]: LICENSE.txt\n[version-img]: https://img.shields.io/badge/Go-%3E%3D%201.22-%23007d9c\n[doc-img]: https://pkg.go.dev/badge/github.com/maxbolgarin/cliex\n[doc]: https://pkg.go.dev/github.com/maxbolgarin/cliex\n[ci-img]: https://github.com/maxbolgarin/cliex/actions/workflows/go.yaml/badge.svg\n[ci]: https://github.com/maxbolgarin/cliex/actions\n[report-img]: https://goreportcard.com/badge/github.com/maxbolgarin/cliex\n[report]: https://goreportcard.com/report/github.com/maxbolgarin/cliex\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxbolgarin%2Fcliex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxbolgarin%2Fcliex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxbolgarin%2Fcliex/lists"}