• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.circleci/H07-Aug-2020-5650

.gitignoreH A D07-Aug-202028 44

LICENSEH A D07-Aug-202015.5 KiB364265

MakefileH A D07-Aug-2020145 128

README.mdH A D07-Aug-20202.4 KiB6246

client.goH A D07-Aug-202024.8 KiB799483

client_test.goH A D07-Aug-202019.9 KiB845671

go.modH A D07-Aug-2020147 96

go.sumH A D07-Aug-2020883 1110

roundtripper.goH A D07-Aug-20201.3 KiB5328

roundtripper_test.goH A D07-Aug-20203.3 KiB142104

README.md

1go-retryablehttp
2================
3
4[![Build Status](http://img.shields.io/travis/hashicorp/go-retryablehttp.svg?style=flat-square)][travis]
5[![Go Documentation](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)][godocs]
6
7[travis]: http://travis-ci.org/hashicorp/go-retryablehttp
8[godocs]: http://godoc.org/github.com/hashicorp/go-retryablehttp
9
10The `retryablehttp` package provides a familiar HTTP client interface with
11automatic retries and exponential backoff. It is a thin wrapper over the
12standard `net/http` client library and exposes nearly the same public API. This
13makes `retryablehttp` very easy to drop into existing programs.
14
15`retryablehttp` performs automatic retries under certain conditions. Mainly, if
16an error is returned by the client (connection errors, etc.), or if a 500-range
17response code is received (except 501), then a retry is invoked after a wait
18period.  Otherwise, the response is returned and left to the caller to
19interpret.
20
21The main difference from `net/http` is that requests which take a request body
22(POST/PUT et. al) can have the body provided in a number of ways (some more or
23less efficient) that allow "rewinding" the request body if the initial request
24fails so that the full request can be attempted again. See the
25[godoc](http://godoc.org/github.com/hashicorp/go-retryablehttp) for more
26details.
27
28Version 0.6.0 and before are compatible with Go prior to 1.12. From 0.6.1 onward, Go 1.12+ is required.
29
30Example Use
31===========
32
33Using this library should look almost identical to what you would do with
34`net/http`. The most simple example of a GET request is shown below:
35
36```go
37resp, err := retryablehttp.Get("/foo")
38if err != nil {
39    panic(err)
40}
41```
42
43The returned response object is an `*http.Response`, the same thing you would
44usually get from `net/http`. Had the request failed one or more times, the above
45call would block and retry with exponential backoff.
46
47## Getting a stdlib `*http.Client` with retries
48
49It's possible to convert a `*retryablehttp.Client` directly to a `*http.Client`.
50This makes use of retryablehttp broadly applicable with minimal effort. Simply
51configure a `*retryablehttp.Client` as you wish, and then call `StandardClient()`:
52
53```go
54retryClient := retryablehttp.NewClient()
55retryClient.RetryMax = 10
56
57standardClient := retryClient.StandardClient() // *http.Client
58```
59
60For more usage and examples see the
61[godoc](http://godoc.org/github.com/hashicorp/go-retryablehttp).
62