HTTP Client
for Go, inspired by the Fetch API, and Axios + Got (Sindre Sorhus).
- Make HTTP requests
- Easy JSON Response
- GZip support
- Decode GZip response
- Encode GZip request (Upload File with GZip)
- HTTP/2 support
- TLS
- Custom TLS Ca Certificate (Self signed certificate) Example
- Custom Client Cert and Key for two-way authentication (Client Cert and Key)
- Custom TLS Ca Certificate (Self signed certificate) Example
- Simple Auth Methods
- Basic Auth
- Bearer Auth
- Support cancel (using context)
- Support timeout
- Support retry on failure
- Support progress and progress events
- Download files easily
- Upload files easily
- RFC compliant caching
- Proxy support
- Environment variables (HTTP_PROXY/HTTPS_PROXY/SOCKS_PROXY)
- Custom proxy
- UNIX Domain Sockets
- WebDAV protocol support
- Plugin system
- Middleware system
To install the package, run:
go get github.com/go-zoox/fetch
- GET
- POST
- PUT
- PATCH
- DELETE
- HEAD
- OPTIONS
- TRACE
- CONNECT
package main
import (
"github.com/go-zoox/fetch"
)
func main() {
response, _ := fetch.Get("https://httpbin.zcorky.com/get")
url := response.Get("url")
method := response.Get("method")
fmt.Println(url, method)
}
package main
import (
"github.com/go-zoox/fetch"
)
func main() {
response, err := fetch.Get("https://httpbin.zcorky.com/get")
if err != nil {
panic(err)
}
fmt.Println(response.JSON())
}
package main
import (
"github.com/go-zoox/fetch"
)
func main() {
response, err := fetch.Post("https://httpbin.zcorky.com/post", &fetch.Config{
Body: map[string]interface{}{
"foo": "bar",
"foo2": "bar2",
"number": 1,
"boolean": true,
"array": []string{
"foo3",
"bar3",
},
"nest": map[string]string{
"foo4": "bar4",
},
},
})
if err != nil {
panic(err)
}
fmt.Println(response.JSON())
}
package main
import (
"github.com/go-zoox/fetch"
)
func main() {
response, err := fetch.Put("https://httpbin.zcorky.com/put", &fetch.Config{
Body: map[string]interface{}{
"foo": "bar",
"foo2": "bar2",
"number": 1,
"boolean": true,
"array": []string{
"foo3",
"bar3",
},
"nest": map[string]string{
"foo4": "bar4",
},
},
})
if err != nil {
panic(err)
}
fmt.Println(response.JSON())
}
package main
import (
"github.com/go-zoox/fetch"
)
func main() {
response, err := fetch.Delete("https://httpbin.zcorky.com/Delete", &fetch.Config{
Body: map[string]interface{}{
"foo": "bar",
"foo2": "bar2",
"number": 1,
"boolean": true,
"array": []string{
"foo3",
"bar3",
},
"nest": map[string]string{
"foo4": "bar4",
},
},
})
if err != nil {
panic(err)
}
fmt.Println(response.JSON())
}
package main
import (
"github.com/go-zoox/fetch"
)
func main() {
response, err := fetch.Get("https://httpbin.zcorky.com/get", &fetch.Config{
Timeout: 5 * time.Second,
})
if err != nil {
panic(err)
}
fmt.Println(response.JSON())
}
package main
import (
"github.com/go-zoox/fetch"
)
func main() {
response, err := fetch.Get("https://httpbin.zcorky.com/ip", &fetch.Config{
Proxy: "http://127.0.0.1:17890",
})
if err != nil {
panic(err)
}
fmt.Println(response.JSON())
}
package main
import (
"github.com/go-zoox/fetch"
)
func main() {
response, err := fetch.Get("https://httpbin.zcorky.com/ip", &fetch.Config{
BasicAuth: &fetch.BasicAuth{
Username: "foo",
Password: "bar",
},
})
if err != nil {
panic(err)
}
fmt.Println(response.JSON())
}
package main
import (
"github.com/go-zoox/fetch"
)
func main() {
response, err := fetch.Download("https://httpbin.zcorky.com/image", "/tmp/image.webp")
if err != nil {
panic(err)
}
}
package main
import (
"github.com/go-zoox/fetch"
)
func main() {
file, _ := os.Open("go.mod")
response, err := Upload("https://httpbin.zcorky.com/upload", file)
if err != nil {
panic(err)
}
fmt.Println(response.JSON())
}
package main
import (
"github.com/go-zoox/fetch"
)
func main() {
file, _ := os.Open("go.mod")
ctx, cancel := context.WithCancel(context.Background())
f := fetch.New()
f.SetBaseURL("https://httpbin.zcorky.com")
f.SetURL("/delay/3")
f.SetContext(ctx)
go func() {
_, err := f.Execute()
fmt.Println(err)
}()
cancel()
}
- gjson - Get JSON Whenever You Need, you don't define type first。
- sindresorhus/got - 🌐 Human-friendly and powerful HTTP request library for Node.js
- axios/axios - Promise based HTTP client for the browser and node.js
- mozillazg/request - A developer-friendly HTTP request library for Gopher
- monaco-io/request - go request, go http client
GoZoox is released under the MIT License.