Http Client Library that provides "enhanced" http client with resiliency & circuit breaker backed functionality
EnhancedHttpClient will retry requests for
- Network issues
- 5xx HTTP status
- Request Timeout
Circuit breaker layer resides before retry policy layer and can be in closed|open|half-open states. Used as-is from gobreaker
Usage:
go get github.com/RassulYunussov/ehttpclient
By default ehttpclient.Create produces EnhancedHttpClient with no retry and no circuit breaker. Client can add policies:
- retry
- circuit breaker
- retry + cicruit breaker
No retry policy. No circuit breaker
defaultClient := ehttpclient.Create(200*time.Millisecond)
The retry policy uses multiplication of attempt & backoffTimeout
// retry count 3
// backoff timeout
retryClient := ehttpclient.Create(200*time.Millisecond, ehttpclient.WithRetry(3, 100*time.Millisecond))
// detailed info about configuration can be found here: https://github.com/sony/gobreaker
retryClient := ehttpclient.Create(200*time.Millisecond, ehttpclient.WithCircuitBreaker(1, 2, time.Second, time.Second))
ehttpClient := ehttpclient.Create(200*time.Millisecond, ehttpclient.WithRetry(3, 100*time.Millisecond), ehttpclient.WithCircuitBreaker(1, 2, time.Second, time.Second))
request, err := http.NewRequest(http.MethodGet, "http://localhost:8080", nil)
response, err := client.Do(request)