Skip to content

Request builder for flexible and composable requests

License

Notifications You must be signed in to change notification settings

ajzo90/go-requests

Repository files navigation

go-requests

Request builder for flexible and composable requests.

CICD CICD Go Report Card GoDoc License Latest Version codecov

Usage

Late/lazy materialisation, values can be pointers to string

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

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)
    })
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