What is go-retryablehttp?
mainThe retryablehttp package is a thin wrapper over the standard Go net/http client library. It provides a familiar HTTP client interface that automatically handles retries and exponential backoff.
Retry Logic
retryablehttp automatically triggers a retry under the following conditions:
- An error is returned by the client (e.g., connection errors).
- A 500-range response code is received (except for
501 Not Implemented).
If these conditions are met, the client waits for a period (using exponential backoff) before attempting the request again. Otherwise, the response is returned to the caller for interpretation.
Request Bodies
Unlike the standard net/http client, retryablehttp supports 'rewinding' request bodies for methods that require them (like POST or PUT). This allows the client to re-send the full request body if an initial attempt fails.