Skip to content
forked from a-poor/vhttp

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

apoor-ccc/vhttp

 
 

Repository files navigation

vhttp

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

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 twitter.

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.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%