ghttp is a simple, user-friendly and concurrent safe HTTP request library for Go.
ghttp wraps net/http and provides convenient APIs and advanced features to simplify your jobs.
- Requests-style APIs.
- GET, POST, PUT, PATCH, DELETE, etc.
- Easy set query params, headers and cookies.
- Easy send form, JSON or multipart payload.
- Automatic cookies management.
- Backoff retry mechanism.
- Before request and after response callbacks.
- Rate limiting for outbound requests.
- Easy decode the response body to bytes, string or unmarshal the JSON-encoded data.
- Friendly debugging.
- Concurrent safe.
go get -u github.com/winterssy/ghttpimport "github.com/winterssy/ghttp"The usages of ghttp are very similar to net/http .
ghttp.Client
client := ghttp.New()
// Now you can manipulate client like net/http
client.CheckRedirect = ghttp.NoRedirect
client.Timeout = 300 * time.Secondghttp.Request
req, err := ghttp.NewRequest("GET", "https://httpbin.org/get")
if err != nil {
log.Fatal(err)
}
// Now you can manipulate req like net/http
req.Close = trueghttp.Response
resp, err := ghttp.Get("https://www.google.com")
if err != nil {
log.Fatal(err)
}
// Now you can access resp like net/http
fmt.Println(resp.StatusCode)Documentation is available at go.dev .