Skip to content
/ vhttp Public

A library for testing Go HTTP requests and responses from the net/http package.

License

Notifications You must be signed in to change notification settings

a-poor/vhttp

Repository files navigation

vhttp

Go Test Go Reference GitHub go.mod Go version Go Report Card Coverage Status

created by Austin Poor

A library for validating HTTP requests and responses from the net/http package.

Quick Example

The following is a quick example testing that req (of type *http.Request)...

  1. Is a "GET" request
  2. Calling json.Valid() on the body returns true
  3. Has the header "Content-Type" and it's equal to "application/json"
  4. The header "Authorization" matches the regular expression ^Bearer .+$
  5. Has the URL path "/users/all"
err := vhttp.ValidateRequest(req, 
    vhttp.MethodIsGet(),                      // #1
    vhttp.BodyIsValidJSON(),                  // #2
    vhttp.HeaderContentTypeJSON(),            // #3
    vhttp.HeaderAuthorizationMatchesBearer(), // #4
    vhttp.URLPathIs("/users/all"),            // #5
)

Read more and find more examples in the go docs!

License

vhttp is released under an MIT license.

Contributing

Contributions are welcome!

Please feel free to submit an issue or a PR. Or you can reach out to me on mastodon.

To-Do

  • Add more tests!
  • Add more examples!
  • Form validators
  • Check for nil pointers? (eg *url.URL)

About

A library for testing Go HTTP requests and responses from the net/http package.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages