This package wraps the Go fasthttp client, providing a simplified interaction model using method chaining and various additional capabilities.
- Simple, method chaining based interface for fasthttp client requests
- Simulation of request delays
- Customization of fasthttp client via functional parameter
- Back-Off-Retry concept to automatically retry requests if required
go get -u github.com/fako1024/fhttpc
err := fhttpc.New("GET", "http://example.org").Run()
if err != nil {
log.Fatalf("error performing GET request: %s", err)
}
var res = struct {
Status int
Message string
}{}
err := fhttpc.New("GET", "http://example.org").
ParseJSON(&res).
Run()
if err != nil {
log.Fatalf("error performing GET request: %s", err)
}
Perform HTTPS POST request with a simple body, disabling certificate validation and copying the response to a bytes.Buffer
buf := new(bytes.Buffer)
err := fhttpc.New("POST", "https://example.org").
SkipCertificateVerification().
Body([]byte{0x1, 0x2}).
ParseFn(fhttpc.Copy(buf)).
Run()
if err != nil {
log.Fatalf("error performing POST request: %s", err)
}
fmt.Println(buf.String())
err := fhttpc.New("GET", "https://example.org").
SkipCertificateVerification().
QueryParams(fhttpc.Params{
"param": "test",
}).
Headers(fhttpc.Params{
"X-HEADER-TEST": "test",
}).
AuthBasic("username", "password").
Run()
if err != nil {
log.Fatalf("error performing GET request: %s", err)
}