Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hashicorp/go-retryablehttp
Retryable HTTP client in Go
https://github.com/hashicorp/go-retryablehttp
Last synced: about 21 hours ago
JSON representation
Retryable HTTP client in Go
- Host: GitHub
- URL: https://github.com/hashicorp/go-retryablehttp
- Owner: hashicorp
- License: mpl-2.0
- Created: 2015-12-07T16:46:24.000Z (about 9 years ago)
- Default Branch: main
- Last Pushed: 2024-11-19T17:08:10.000Z (3 months ago)
- Last Synced: 2025-02-05T21:45:50.454Z (6 days ago)
- Language: Go
- Size: 218 KB
- Stars: 2,054
- Watchers: 291
- Forks: 258
- Open Issues: 69
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
- awesome-go - go-retryablehttp - Retryable HTTP client in Go. (Networking / HTTP Clients)
- zero-alloc-awesome-go - go-retryablehttp - Retryable HTTP client in Go. (Networking / HTTP Clients)
- awesome-repositories - hashicorp/go-retryablehttp - Retryable HTTP client in Go (Go)
- awesome-go - go-retryablehttp - Retryable HTTP client (Middlewares & framework add-ons)
- awesome-go-extra - go-retryablehttp - 12-07T16:46:24Z|2022-08-01T14:40:53Z| (Networking / HTTP Clients)
- awesome-go - go-retryablehttp - Retryable HTTP client in Go. Stars:`2.1K`. (Networking / HTTP Clients)
README
go-retryablehttp
================[![Build Status](http://img.shields.io/travis/hashicorp/go-retryablehttp.svg?style=flat-square)][travis]
[![Go Documentation](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)][godocs][travis]: http://travis-ci.org/hashicorp/go-retryablehttp
[godocs]: http://godoc.org/github.com/hashicorp/go-retryablehttpThe `retryablehttp` package provides a familiar HTTP client interface with
automatic retries and exponential backoff. It is a thin wrapper over the
standard `net/http` client library and exposes nearly the same public API. This
makes `retryablehttp` very easy to drop into existing programs.`retryablehttp` performs automatic retries under certain conditions. Mainly, if
an error is returned by the client (connection errors, etc.), or if a 500-range
response code is received (except 501), then a retry is invoked after a wait
period. Otherwise, the response is returned and left to the caller to
interpret.The main difference from `net/http` is that requests which take a request body
(POST/PUT et. al) can have the body provided in a number of ways (some more or
less efficient) that allow "rewinding" the request body if the initial request
fails so that the full request can be attempted again. See the
[godoc](http://godoc.org/github.com/hashicorp/go-retryablehttp) for more
details.Version 0.6.0 and before are compatible with Go prior to 1.12. From 0.6.1 onward, Go 1.12+ is required.
From 0.6.7 onward, Go 1.13+ is required.Example Use
===========Using this library should look almost identical to what you would do with
`net/http`. The most simple example of a GET request is shown below:```go
resp, err := retryablehttp.Get("/foo")
if err != nil {
panic(err)
}
```The returned response object is an `*http.Response`, the same thing you would
usually get from `net/http`. Had the request failed one or more times, the above
call would block and retry with exponential backoff.## Getting a stdlib `*http.Client` with retries
It's possible to convert a `*retryablehttp.Client` directly to a `*http.Client`.
This makes use of retryablehttp broadly applicable with minimal effort. Simply
configure a `*retryablehttp.Client` as you wish, and then call `StandardClient()`:```go
retryClient := retryablehttp.NewClient()
retryClient.RetryMax = 10standardClient := retryClient.StandardClient() // *http.Client
```For more usage and examples see the
[pkg.go.dev](https://pkg.go.dev/github.com/hashicorp/go-retryablehttp).