{"id":15439682,"url":"https://github.com/h2non/gentleman-retry","last_synced_at":"2025-06-24T01:07:40.212Z","repository":{"id":57484636,"uuid":"52568727","full_name":"h2non/gentleman-retry","owner":"h2non","description":"gentleman's plugin providing retry policy capabilities in your HTTP clients","archived":false,"fork":false,"pushed_at":"2017-09-11T08:44:28.000Z","size":19,"stargazers_count":11,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-18T11:25:45.592Z","etag":null,"topics":["backoffice","client","gentleman","http","retry","toolkit"],"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/h2non.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}},"created_at":"2016-02-26T01:11:17.000Z","updated_at":"2023-11-18T18:13:33.000Z","dependencies_parsed_at":"2022-09-02T00:01:41.401Z","dependency_job_id":null,"html_url":"https://github.com/h2non/gentleman-retry","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2non%2Fgentleman-retry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2non%2Fgentleman-retry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2non%2Fgentleman-retry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2non%2Fgentleman-retry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/h2non","download_url":"https://codeload.github.com/h2non/gentleman-retry/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249769319,"owners_count":21323064,"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":["backoffice","client","gentleman","http","retry","toolkit"],"created_at":"2024-10-01T19:08:40.897Z","updated_at":"2025-04-19T18:48:29.680Z","avatar_url":"https://github.com/h2non.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [gentleman](https://github.com/h2non/gentleman)-retry [![Build Status](https://travis-ci.org/h2non/gentleman-retry.png)](https://travis-ci.org/h2non/gentleman-retry) [![GoDoc](https://godoc.org/github.com/h2non/gentleman-retry?status.svg)](https://godoc.org/github.com/h2non/gentleman-retry) [![Coverage Status](https://coveralls.io/repos/github/h2non/gentleman-retry/badge.svg?branch=master)](https://coveralls.io/github/h2non/gentleman-retry?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/h2non/gentleman-retry)](https://goreportcard.com/report/github.com/h2non/gentleman-retry)\n\n[gentleman](https://github.com/h2non/gentleman)'s v2 plugin providing retry policy capabilities to your HTTP clients.\n\nConstant backoff strategy will be used by default with a maximum of 3 attempts, but you use a custom or third-party retry strategies.\nRequest bodies will be cached in the stack in order to re-send them if needed.\n\nBy default, retry will happen in case of network error or server response error (\u003e= 500 || = 429).\nYou can use a custom `Evaluator` function to determine with custom logic when should retry or not.\n\nBehind the scenes it implements a custom [http.RoundTripper](https://golang.org/pkg/net/http/#RoundTripper)\ninterface which acts like a proxy to `http.Transport`, in order to take full control of the response and retry the request if needed.\n\n## Installation\n\n```bash\ngo get -u gopkg.in/h2non/gentleman-retry.v2\n```\n\n## Versions\n\n- **[v1](https://github.com/h2non/gentleman-retry/tree/v1)** - First version, uses `gentleman@v1`.\n- **[v2](https://github.com/h2non/gentleman-retry/tree/master)** - Latest version, uses `gentleman@v2`.\n\n## API\n\nSee [godoc reference](https://godoc.org/github.com/h2non/gentleman-retry) for detailed API documentation.\n\n## Examples\n\n#### Default retry strategy\n\n```go\npackage main\n\nimport (\n  \"fmt\"\n\n  \"gopkg.in/h2non/gentleman.v2\"\n  \"gopkg.in/h2non/gentleman-retry.v2\"\n)\n\nfunc main() {\n  // Create a new client\n  cli := gentleman.New()\n\n  // Define base URL\n  cli.URL(\"http://httpbin.org\")\n\n  // Register the retry plugin, using the built-in constant back off strategy\n  cli.Use(retry.New(retry.ConstantBackoff))\n\n  // Create a new request based on the current client\n  req := cli.Request()\n\n  // Define the URL path at request level\n  req.Path(\"/status/503\")\n\n  // Set a new header field\n  req.SetHeader(\"Client\", \"gentleman\")\n\n  // Perform the request\n  res, err := req.Send()\n  if err != nil {\n    fmt.Printf(\"Request error: %s\\n\", err)\n    return\n  }\n  if !res.Ok {\n    fmt.Printf(\"Invalid server response: %d\\n\", res.StatusCode)\n    return\n  }\n}\n```\n\n#### Exponential retry strategy\n\nI would recommend you using [go-resiliency](https://github.com/eapache/go-resiliency/tree/master/retrier) package for custom retry estrategies:\n```go\ngo get -u gopkg.in/eapache/go-resiliency.v1/retrier\n```\n\n```go\npackage main\n\nimport (\n  \"fmt\"\n  \"time\"\n\n  \"gopkg.in/h2non/gentleman.v2\"\n  \"gopkg.in/h2non/gentleman-retry.v2\"\n  \"gopkg.in/eapache/go-resiliency.v1/retrier\"\n\n)\n\nfunc main() {\n  // Create a new client\n  cli := gentleman.New()\n\n  // Define base URL\n  cli.URL(\"http://httpbin.org\")\n\n  // Register the retry plugin, using a custom exponential retry strategy\n  cli.Use(retry.New(retrier.New(retrier.ExponentialBackoff(3, 100*time.Millisecond), nil)))\n\n  // Create a new request based on the current client\n  req := cli.Request()\n\n  // Define the URL path at request level\n  req.Path(\"/status/503\")\n\n  // Set a new header field\n  req.SetHeader(\"Client\", \"gentleman\")\n\n  // Perform the request\n  res, err := req.Send()\n  if err != nil {\n    fmt.Printf(\"Request error: %s\\n\", err)\n    return\n  }\n  if !res.Ok {\n    fmt.Printf(\"Invalid server response: %d\\n\", res.StatusCode)\n    return\n  }\n}\n```\n\n## License\n\nMIT - Tomas Aparicio\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh2non%2Fgentleman-retry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fh2non%2Fgentleman-retry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh2non%2Fgentleman-retry/lists"}