{"id":30883362,"url":"https://github.com/globocom/httpclient","last_synced_at":"2025-09-08T09:45:05.791Z","repository":{"id":62867151,"uuid":"546862245","full_name":"globocom/httpclient","owner":"globocom","description":"A HTTP client in Golang.","archived":false,"fork":false,"pushed_at":"2024-04-18T12:57:25.000Z","size":2828,"stargazers_count":14,"open_issues_count":1,"forks_count":5,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-04-06T08:36:37.931Z","etag":null,"topics":["circuit-breaker","golang","http-client","library","resilience","retry-strategies"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/globocom.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":"2022-10-06T19:16:42.000Z","updated_at":"2025-03-22T02:21:31.000Z","dependencies_parsed_at":"2024-04-18T13:56:50.765Z","dependency_job_id":"4d72cb60-f97e-47ac-acbe-345c4d158870","html_url":"https://github.com/globocom/httpclient","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/globocom/httpclient","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/globocom%2Fhttpclient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/globocom%2Fhttpclient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/globocom%2Fhttpclient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/globocom%2Fhttpclient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/globocom","download_url":"https://codeload.github.com/globocom/httpclient/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/globocom%2Fhttpclient/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274166945,"owners_count":25233959,"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","status":"online","status_checked_at":"2025-09-08T02:00:09.813Z","response_time":121,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["circuit-breaker","golang","http-client","library","resilience","retry-strategies"],"created_at":"2025-09-08T09:45:03.753Z","updated_at":"2025-09-08T09:45:05.784Z","avatar_url":"https://github.com/globocom.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# httpclient\n\nA HTTP client implementation in GoLang.\n\n# Examples\n\n### 1. OAuth Authorization\n\n```go\npackage example\n\nimport (\n\t\"context\"\n\t\"log\"\n\t\"time\"\n\n\t\"github.com/globocom/httpclient\"\n\t\"golang.org/x/oauth2/clientcredentials\"\n)\n\nfunc main() {\n    timeout := 200 * time.Millisecond\n    contextTimeout, cancel := context.WithTimeout(context.Background(), timeout)\n    defer cancel()\n\n    credentials := clientcredentials.Config{\n        ClientID:     \"client_id\",\n        ClientSecret: \"client_secret\",\n        TokenURL:     \"client_url/token\",\n        Scopes:       []string{\"grant_permissions:client_credentials\"},\n    }\n\n    client := httpclient.NewHTTPClient(httpclient.LoggerAdapter{Writer: log.Writer()},\n        httpclient.WithOAUTHTransport(credentials, timeout))\n\n    resp, err := client.NewRequest().\n        SetContext(contextTimeout).\n        Put(\"/authorize\")\n\n    log.Printf(\"resp: %#v\", resp)\n    log.Printf(\"err: %s\", err)\n}\n```\n### 2. Circuit Breaker with Timeout and Retries\n```go\npackage example\n\nimport (\n\t\"log\"\n\t\"time\"\n\n\t\"github.com/slok/goresilience/circuitbreaker\"\n\t\"github.com/globocom/httpclient\"\n)\nfunc main() {\n    cbConfig := circuitbreaker.Config {\n        ErrorPercentThresholdToOpen:        5,\n        MinimumRequestToOpen:               50,\n        SuccessfulRequiredOnHalfOpen:       50,\n        WaitDurationInOpenState:            30 * time.Second,\n        MetricsSlidingWindowBucketQuantity: 5,\n        MetricsBucketDuration:              5 * time.Second,\n    }\n\n    timeout := 200 * time.Millisecond\n    retries := 1\n    backoff := 5 * time.Millisecond\n    maxBackoff := 10 * time.Millisecond\n\n    client := httpclient.NewHTTPClient(httpclient.LoggerAdapter{Writer: log.Writer()},\n        httpclient.WithDefaultTransport(timeout),\n        httpclient.WithTimeout(timeout),\n        httpclient.WithCircuitBreaker(cbConfig),\n        httpclient.WithRetries(retries, backoff, maxBackoff),\n    )\n\n    resp, err := client.NewRequest().\n        Get(\"/example\")\n\n    log.Printf(\"resp: %#v\", resp)\n    log.Printf(\"err: %s\", err)\n}\n```\n\n### 3. Callback Chain\n```go\npackage example\n\nimport (\n\t\"log\"\n\n\t\"github.com/globocom/httpclient\"\n)\n\nfunc main() {\n    client := httpclient.NewHTTPClient(\n        httpclient.LoggerAdapter{Writer: log.Writer()},\n        httpclient.WithChainCallback(loggerCallback),\n    )\n    resp, err := client.NewRequest().Get(\"example.com\")\n    log.Printf(\"resp: %#v\", resp)\n    log.Printf(\"err: %s\", err)\n}\n\nfunc loggerCallback(fn func() (*httpclient.Response, error)) (*httpclient.Response, error) {\n    resp, err := fn()\n\nif resp != nil {\n    restyRequest := resp.Request().RestyRequest()\n    requestURL := restyRequest.RawRequest.URL\n    host := requestURL.Host\n    // If the client is initialized without WithHostURL, request.HostURL() is going to be nil\n    if requestHostURL := resp.Request().HostURL(); requestHostURL != nil {\n        host = requestHostURL.Host\n    }\n\n    responseTime := resp.ResponseTime().Microseconds()\n    log.Printf(\"%s [%s] %d -- %s (%dμs)\", host, restyRequest.Method,\n        resp.StatusCode(), requestURL.String(), responseTime)\n}\n\n    return resp, err\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglobocom%2Fhttpclient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglobocom%2Fhttpclient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglobocom%2Fhttpclient/lists"}