A http client written with golang
- directly install
go get -u github.com/iyidan/zrequest
- use govendor package manager
cd $GOPATH/src/mysomeproject
govendor fetch github.com/iyidan/[email protected]
- test with online server (http://httpbin.org)
go test github.com/iyidan/zrequest
# go test -v github.com/iyidan/zrequest
- test with local server(need python environment)
pip install httpbin
pip install gunicorn
go test -local github.com/iyidan/zrequest
# go test -v -local github.com/iyidan/zrequest
See the godoc for more information
package main
import (
"fmt"
"github.com/iyidan/zrequest"
)
// HTTPBinResponse The structure of httpbin response
type HTTPBinResponse struct {
Args map[string]string
Data string
Files map[string]string
Form map[string]string
Headers map[string]string
JSON interface{}
Origin string
URL string `json:"url"`
}
func main() {
// the request data
data := map[string]interface{}{"username": "iyidan","age":22}
// the response type
res := HTTPBinResponse{}
// request and unmarshal response into res
err := zrequest.Open().SetBody(data).Post("http://httpbin.org/post?arg1=arg1").Unmarshal(&res)
// handle error
if err != nil {
panic(err)
}
fmt.Printf("The response is: %#v", res)
}
More Examples: See the test files *_test.go