This package is a library of ZKits project. This library provides an efficient and easy-to-use HTTP client.
go get -u -v github.com/edoger/zkits-requester
package main
import (
"fmt"
"github.com/edoger/zkits-requester"
)
func main() {
client := requester.Default()
// client.Get("https://test.com", nil)
res, err := client.New("https://test.com").Get()
if err != nil {
panic(err)
}
fmt.Println(res.String())
data := map[string]interface{}{"key": "value"}
// client.PostJSON("https://test.com", data)
res, err = client.New("https://test.com").WithJSONBody(data).Post()
if err != nil {
panic(err)
}
obj := make(map[string]interface{})
// Bind response json to object.
if err = res.JSON(&obj); err != nil {
panic(err)
}
// client.UploadFile("https://test.com", "upload", "path/to/file")
res, err = client.New("https://test.com").WithFormDataFile("upload", "path/to/file").Upload()
if err != nil {
panic(err)
}
fmt.Println(res.String())
}