https://github.com/vthiery/avoca
Yet another HTTP client \o/
https://github.com/vthiery/avoca
Last synced: about 1 year ago
JSON representation
Yet another HTTP client \o/
- Host: GitHub
- URL: https://github.com/vthiery/avoca
- Owner: vthiery
- License: mit
- Created: 2020-08-25T06:02:31.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2023-08-15T02:07:35.000Z (almost 3 years ago)
- Last Synced: 2025-02-13T17:30:25.497Z (over 1 year ago)
- Language: Go
- Homepage:
- Size: 49.8 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Avoca
[](https://pkg.go.dev/github.com/vthiery/avoca)
[](https://github.com/vthiery/avoca)



## Description
Yet another HTTP client \o/
## Installation
```sh
go get -u github.com/vthiery/avoca
```
## Usage
```go
package main
import (
"context"
"fmt"
"net/http"
"time"
"github.com/vthiery/avoca"
"github.com/vthiery/retry"
)
func main() {
client := avoca.NewClient(
avoca.WithHTTPClient(
&http.Client{
// Timeout the HTTP connection after 200 ms.
Timeout: 200 * time.Millisecond,
},
),
// Perform maximum 10 attempts with an exponential backoff.
avoca.WithRetrier(
retry.New(
retry.WithMaxAttempts(10),
retry.WithBackoff(
retry.NewExponentialBackoff(
100*time.Millisecond, // minWait
1*time.Second, // maxWait
2*time.Millisecond, // maxJitter
),
),
),
),
// Only retry when the status code is >= 500
avoca.WithRetryPolicy(
func(statusCode int) bool {
return statusCode >= http.StatusInternalServerError
},
),
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
res, err := client.Get(ctx, "http://google.com", nil)
if err != nil {
fmt.Printf("failed to GET: %v\n", err)
}
defer res.Body.Close()
}
```