A request tool based on Go native net/http
.
With Go module support, simply add the following import
import "github.com/iamdanielyin/req"
to your code, and then go [build|run|test]
will automatically fetch the necessary dependencies.
Otherwise, run the following Go command to install the req
package:
$ go get -u github.com/iamdanielyin/req
First you need to import req
package for using req
, one simplest example likes the follow example.go:
package main
import (
"github.com/iamdanielyin/req"
"log"
)
func main() {
var posts []struct {
UserId int `json:"userId"`
Id int `json:"id"`
Title string `json:"title"`
Body string `json:"body"`
}
if err := req.GET("https://jsonplaceholder.typicode.com/posts", &posts); err != nil {
log.Fatal(err)
}
}
And use the Go command to run the demo:
$ go run example.go
req.GET(url, dst[, headers])
req.POST(url, body, dst[, headers])
req.PATCH(url, body, dst[, headers])
req.PUT(url, body, dst[, headers])
req.DELETE(url, body, dst[, headers])
req.CALL(method, url, body, dst[, headers])
req.URL(format, values...)
.GET(dst[, headers])
.POST(body, dst[, headers])
.PATCH(body, dst[, headers])
.PUT(body, dst[, headers])
.DELETE(dst[, headers])
.CALL(method, body, dst[, headers])
.AddHeader(key, value)
.DelHeader(key)
.SetHeaders(headers)
.SetBody(body)
.URL()
.Headers()