{"id":13413653,"url":"https://github.com/ybbus/httpretry","last_synced_at":"2025-03-14T19:32:56.716Z","repository":{"id":57511930,"uuid":"238421783","full_name":"ybbus/httpretry","owner":"ybbus","description":"Enriches the standard go http client with retry functionality.","archived":false,"fork":false,"pushed_at":"2024-05-18T06:41:44.000Z","size":57,"stargazers_count":44,"open_issues_count":1,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-07-31T20:52:37.220Z","etag":null,"topics":["golang","http-client","resilience","retry"],"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/ybbus.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":"2020-02-05T10:17:42.000Z","updated_at":"2024-06-27T21:17:54.000Z","dependencies_parsed_at":"2024-06-18T18:44:08.123Z","dependency_job_id":null,"html_url":"https://github.com/ybbus/httpretry","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ybbus%2Fhttpretry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ybbus%2Fhttpretry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ybbus%2Fhttpretry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ybbus%2Fhttpretry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ybbus","download_url":"https://codeload.github.com/ybbus/httpretry/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221498771,"owners_count":16833059,"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":["golang","http-client","resilience","retry"],"created_at":"2024-07-30T20:01:45.493Z","updated_at":"2024-10-26T05:31:13.003Z","avatar_url":"https://github.com/ybbus.png","language":"Go","readme":"[![Go Report Card](https://goreportcard.com/badge/github.com/ybbus/httpretry)](https://goreportcard.com/report/github.com/ybbus/httpretry)\n[![Go build](https://github.com/ybbus/httpretry/actions/workflows/go.yml/badge.svg)](https://github.com/ybbus/httpretry)\n[![Codecov](https://codecov.io/github/ybbus/httpretry/branch/master/graph/badge.svg?token=ARYOQ8R1DT)](https://codecov.io/github/ybbus/httpretry)\n[![GoDoc](https://godoc.org/github.com/ybbus/httpretry?status.svg)](https://godoc.org/github.com/ybbus/httpretry)\n[![GitHub license](https://img.shields.io/github/license/mashape/apistatus.svg)]()\n\n# httpRetry\n\nEnriches the standard go http client with retry functionality using a wrapper around the Roundtripper interface.\n\nThe advantage of this library is that it makes use of the default http.Client.\nThis means you can provide it to any library that accepts the go standard http.Client.\nThis in turn gives you the possibility to add resilience to a lot of http based go libraries with just a single line of code.\nOf course it can also be used as standalone http client in your own projects.\n\n## Installation\n\n```sh\ngo get -u github.com/ybbus/httpretry\n```\n\n## Quickstart\n\nTo get a standard http client with retry functionality:\n\n```golang\nclient := httpretry.NewDefaultClient()\n// use this as usual when working with http.Client\n```\n\nThis single line of code returns a default http.Client that uses an exponential backoff and sends up to 5 retries if the request was not successful.\nRequests will be retried if the error seems to be temporary or the requests returns a status code that may change over time (e.g. GetwayTimeout).\n\n### Modify / customize the Roundtripper (http.Transport)\n\nSince httpretry wraps the actual Roundtripper of the http.Client, you should not try to replace / modify the client.Transport field after creation.\n\nYou either configure the http.Client upfront and then \"make\" it retryable like in this code:\n\n```golang\ncustomHttpClient := \u0026http.Client{}\ncustomHttpClient.Transport = \u0026http.Transport{...}\n\nretryClient := httpretry.NewCustomClient(cumstomHttpClient)\n```\n\nor you use one of the available helper functions to gain access to the underlying Roundtripper / http.Transport:\n\n```golang\n// replaces the original roundtripper\nhttpretry.ReplaceOriginalRoundtripper(retryClient, myRoundTripper)\n\n// modifies the embedded http.Transport by providing a function that receives the client.Transport as parameter\nhttpretry.ModifyOriginalTransport(retryClient, func(t *http.Transport) { t.TLSHandshakeTimeout = 5 * time.Second })\n\n// returns the embedded Roundtripper\nhttpretry.GetOriginalRoundtripper(retryClient)\n\n// returns the embedded Roundtripper as http.Transport if it is of that type\nhttpretry.GetOriginalTransport(retryClient)\n```\n\n### Customize retry settings\n\nYou may provide your own Backoff- and RetryPolicy.\n\n```golang\nclient := httpretry.NewDefaultClient(\n    // retry up to 5 times\n    httpretry.WithMaxRetryCount(5),\n    // retry on status \u003e= 500, if err != nil, or if response was nil (status == 0)\n    httpretry.WithRetryPolicy(func(statusCode int, err error) bool {\n      return err != nil || statusCode \u003e= 500 || statusCode == 0\n    }),\n    // every retry should wait one more second\n    httpretry.WithBackoffPolicy(func(attemptNum int) time.Duration {\n      return time.Duration(attemptNum+1) * 1 * time.Second\n    }),\n)\n```\n","funding_links":[],"categories":["Networking","网络相关库","网络","HTTP Clients"],"sub_categories":["HTTP Clients","Http Client","HTTP客户端"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fybbus%2Fhttpretry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fybbus%2Fhttpretry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fybbus%2Fhttpretry/lists"}