Skip to content

iyidan/zrequest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zrequest

GoDoc Go Report

A http client written with golang

Install

  • directly install
go get -u github.com/iyidan/zrequest
cd $GOPATH/src/mysomeproject
govendor fetch github.com/iyidan/[email protected]

Tests

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

Docs

See the godoc for more information

Example

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

About

a golang http client easy to use.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages