Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wenerme/go-req
Declarative golang HTTP client
https://github.com/wenerme/go-req
client golang http
Last synced: about 2 months ago
JSON representation
Declarative golang HTTP client
- Host: GitHub
- URL: https://github.com/wenerme/go-req
- Owner: wenerme
- License: mit
- Created: 2021-07-11T10:42:40.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-07-06T11:07:02.000Z (over 2 years ago)
- Last Synced: 2024-07-31T20:52:46.980Z (4 months ago)
- Topics: client, golang, http
- Language: Go
- Homepage:
- Size: 27.3 KB
- Stars: 22
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - go-req - Declarative golang HTTP client. (Networking / HTTP Clients)
- zero-alloc-awesome-go - go-req - Declarative golang HTTP client. (Networking / HTTP Clients)
- awesome-go-extra - go-req - 07-11T10:42:40Z|2022-07-06T11:07:02Z| (Networking / HTTP Clients)
README
# go-req
[![GoDoc][doc-img]][doc] [![Build Status][ci-img]][ci] [![Coverage Status][cov-img]][cov] [![Go Report Card][report-card-img]][report-card]
[doc-img]: https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square
[doc]: https://pkg.go.dev/github.com/wenerme/go-req?tab=doc
[ci-img]: https://github.com/wenerme/go-req/actions/workflows/ci.yml/badge.svg
[ci]: https://github.com/wenerme/go-req/actions/workflows/ci.yml
[cov-img]: https://codecov.io/gh/wenerme/go-req/branch/main/graph/badge.svg
[cov]: https://codecov.io/gh/wenerme/go-req/branch/main
[report-card-img]: https://goreportcard.com/badge/github.com/wenerme/go-req
[report-card]: https://goreportcard.com/report/github.com/wenerme/go-reqDeclarative golang HTTP client
```go
package req_testimport (
"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](https://github.com/wenerme/go-wecom)
- Wechat Work/Wecom/企业微信 Golang SDK