A concise HTTP request client for Go. It provides elegant and chainalbe API to make you request with happiness.
go get -u github.com/DavidCai1993/request
API documentation can be found here: https://godoc.org/github.com/DavidCai1993/request
json, err = request.
Post("http://mysite.com").
Timeout(30*time.Second).
Send(map[string]string{"name": "David"}).
Set("X-HEADER-KEY", "foo").
Accept("application/json").
JSON()
type MyResult struct {
Code int `json:"code"`
Error string `json:"error"`
Data map[string]interface{} `json:"data"`
}
json, err = request.
Get("http://mysite.com").
JSON(new(MyResult))
res, err = request.
Get("http://mysite.com").
End()
text, err = request.
Get("http://mysite.com/get").
Cookie(&http.Cookie{Name: "name", Value: "David"}).
Text()
json, err = request.
Get("http://mysite.com/somebooks").
Auth("name", "passwd").
JSON()
json, err = request.
Post("http://mysite.com/form").
Field(url.Values{"key": []string{"value1"}}).
Attach("test.md", "./README.md", "README.md").
JSON()
json, err = request.
Get("http://mysite.com/somebooks").
Proxy("http://myproxy.com:8080").
JSON()
req, err = request.
Post("http://mysite.com/form").
Auth("name", "passwd").
Req()