Skip to content

A simple, user-friendly and concurrent safe HTTP request library for Go

License

Notifications You must be signed in to change notification settings

winterssy/ghttp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ghttp

ghttp is a simple, user-friendly and concurrent safe HTTP request library for Go.

Build codecov Go Report Card GoDoc License

Features

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.

Install

go get -u github.com/winterssy/ghttp

Usage

import "github.com/winterssy/ghttp"

Quick Start

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.Second
  • ghttp.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 = true
  • ghttp.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 .

License

MIT

Releases

No releases published

Packages

No packages published

Languages