go-req
Declarative golang HTTP client
About go-req
go-req
Declarative golang HTTP client
package req_test
import (
"fmt"
"github.com/wenerme/go-req"
"net/http"
)
func ExampleRequest() {
// reusable client
client := req.Request{
BaseURL: "https://httpbin.org",
Options: []interface{}{req.JSONEncode, req.JSONDecode},
}
// dump request and response with body
client = client.WithHook(req.DebugHook(&req.DebugOptions{Body: true}))
// send request with declarative override
var out PostResponse
var r *http.Response
err := client.With(req.Request{
Method: http.MethodPost,
URL: "/post",
Body: HelloRequest{
Name: "go-req",
},
}).Fetch(&out,&r)
if err != nil {
panic(err)
}
// print go-req
fmt.Println(out.JSON.Name)
// print 200
fmt.Println(r.StatusCode)
}
type HelloRequest struct {
Name string
}
type HelloResponse struct {
Name string
}
type PostResponse struct {
JSON HelloResponse `json:"json"`
}
Used by
- wenerme/go-wecom
- Wechat Work/Wecom/企业微信 Golang SDK
Frequently Asked Questions
What is go-req?
go-req is a Networking library for the Go programming language. Declarative golang HTTP client
How do I install go-req?
Install go-req with the Go module system using `go get wenerme/go-req`. Check the repository for the current installation instructions.
What category does go-req belong to?
go-req is listed under Networking, specifically HTTP Clients.