https://github.com/ajzo90/go-requests
Request builder for flexible and composable requests
https://github.com/ajzo90/go-requests
builder go golang http request
Last synced: 22 days ago
JSON representation
Request builder for flexible and composable requests
- Host: GitHub
- URL: https://github.com/ajzo90/go-requests
- Owner: ajzo90
- License: mit
- Created: 2022-03-18T21:44:16.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-04-08T13:35:40.000Z (almost 4 years ago)
- Last Synced: 2023-07-27T21:53:55.923Z (over 2 years ago)
- Topics: builder, go, golang, http, request
- Language: Go
- Homepage:
- Size: 56.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-requests
Request builder for flexible and composable requests.
[](https://github.com/ajzo90/go-requests/actions/workflows/ci.yml)
[](https://github.com/ajzo90/go-requests/actions/workflows/go.yml)
[](https://goreportcard.com/report/github.com/ajzo90/go-requests)
[](https://godoc.org/github.com/ajzo90/go-requests)
[](LICENSE)
[](https://github.com/ajzo90/go-requests/releases)
[](https://codecov.io/gh/ajzo90/go-requests)
## Usage
### Late/lazy materialisation, values can be pointers to string
```go
var token = "secret"
var builder = requests.NewPost("example.com/test").
Query("key", "val").
Header("token", &token)
jsonResp, err := builder.ExecJSON()
token = "super-secret" // update token
jsonResp, err := builder.ExecJSON()
```
### Secret masking
```go
requests.New(url).
Method(http.MethodGet).
Path("/foo/bar").
Query("k", "${key}").
Header("user-agent", "x").
Header("Auth", "${key}").
Header("Miss", "${miss}").
SecretHeader("my-header", "secret2").
BasicAuth("christian", "secret3").
JSONBody("hello").
WithExtended(func(req *requests.ExtendedRequest) {
req.Doer(doer)
req.Secret("key", "secret")
req.Timeout(time.Second * 6)
_ = req.Write(os.Stdout)
})
```
```shell
GET /foo/bar?k=xxxxxx HTTP/1.1
Host: 127.0.0.1:63181
User-Agent: x
Content-Length: 7
Auth: xxxxxx
Authorization: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Content-Type: application/json
Miss: ${miss}
My-Header: xxxxxxx
"hello"
```
## Todo
- [ ] Context
- [ ] Error validation. 200, 2xx, customer, other?
- [ ] Retry
- [ ] Throttle