go get github.com/mediabuyerbot/httpclient
make deps
make test
make covertest
COVERALLS_HTTPCLIENT_TOKEN=${COVERALLS_REPO_TOKEN}
make sync-coveralls
make mocks
cli, err := New()
if err != nil {
panic(err)
}
resp, err := cli.Get(context.TODO(), "https://google.com", nil)
if err != nil {
panic(err)
}
...
cli, err := New()
if err != nil {
panic(err)
}
headers := make(http.Header)
headers.Add("X-Header", "value")
resp, err := cli.Get(context.TODO(), "https://google.com", headers)
if err != nil {
panic(err)
}
...
cli, err := New()
if err != nil {
panic(err)
}
payload := ioutil.NopCloser(bytes.NewReader([]byte(`payload`)))
resp, err := cli.Post(context.TODO(), payload, "https://google.com", nil)
if err != nil {
panic(err)
}
...
cli, err := New()
if err != nil {
panic(err)
}
headers := make(http.Header)
headers.Add("X-Header", "value")
payload := ioutil.NopCloser(bytes.NewReader([]byte(`payload`)))
resp, err := cli.POST(context.TODO(), payload, "https://google.com", headers)
if err != nil {
panic(err)
}
...
cli, err := New()
if err != nil {
panic(err)
}
payload := ioutil.NopCloser(bytes.NewReader([]byte(`payload`)))
resp, err := cli.PUT(context.TODO(), payload, "https://google.com", nil)
if err != nil {
panic(err)
}
...
cli, err := New()
if err != nil {
panic(err)
}
headers := make(http.Header)
headers.Add("X-Header", "value")
payload := ioutil.NopCloser(bytes.NewReader([]byte(`payload`)))
resp, err := cli.PUT(context.TODO(), payload, "https://google.com", headers)
if err != nil {
panic(err)
}
...
cli, err := New()
if err != nil {
panic(err)
}
resp, err := cli.Delete(context.TODO(), "https://google.com", nil)
if err != nil {
panic(err)
}
...
cli, err := New()
if err != nil {
panic(err)
}
headers := make(http.Header)
headers.Add("X-Header", "value")
resp, err := cli.Delete(context.TODO(), "https://google.com", headers)
if err != nil {
panic(err)
}
...
cli, err := New()
if err != nil {
panic(err)
}
req, err := http.NewRequest(http.MethodHead, "https://google.com", nil)
if err != nil {
panic(err)
}
resp, err := cli.Do(req)
if err != nil {
panic(err)
}
...
_, err := New(
WithTimeout(time.Second),
WithRetryCount(2),
WithRequestHook(func(request *http.Request, i int) {})
WithResponseHook(func(request *http.Request, response *http.Response) {}),
WithCheckRetry(func(req *http.Request, resp *http.Response, err error) (bool, error) {}),
WithBackOff(func(attemptNum int, resp *http.Response) time.Duration {}),
WithErrorHook(func(req *http.Request, err error, retry int) {}),
WithErrorHandler(func(resp *http.Response, err error, numTries int) (*http.Response, error) {}),
WithBaseURL("http://127.0.0.1"),
)