httpr is yet another dependency-free library for building, sending HTTP requests and handling responses.
httpr tries to follow Go language idioms by providing more convenient (read "less boilerplate") means to work with HTTP requests, without replacing \or abstracting standard net/http types too much, where it isn't really needed.
It also provides custom HTTP client component, which can be configured with different options such as backoff strategy, rate-limiting, automatic response decompression and more.
$ go get github.com/hickar/httpr
Note: httpr is dependency-free library.
client := httpr.New()
resp, err := client.Get(context.TODO(), "https://mysite.com", nil)
if err != nil {
// handle error...
}
fmt.Println(resp.String())
client := httpr.New()
// body can be one of following types (or types implementing interfaces):
// string, []byte, map[string]any, io.Reader or nil.
body := "this is request body"
resp, err := client.Post(context.TODO(), "https://mysite.com", body)
if err != nil {
// handle error...
}
req, err := httpr.
NewRequest().
Post("https://mysite.com", []byte("sample body content")).
SetHeaders(map[string]string{
"Accept": "application/json",
}).
Build()
// req is a pointer to standard net/http Request instance.
Building custom client with features like external ratelimiter (like uber's ratelimit).
client := httpr.New(
httpr.WithRateLimiter(ratelimit.New()),
httpr.WithTransport(httpr.BasicAuthTransport("user", "password")),
httpr.WithRetryCount(3),
httpr.WithTimeout(time.Minute * 3),
)
resp, err := client.Get(ctx, "https://mysite.com", nil)
// ...