Skip to content

Latest commit

 

History

History
49 lines (35 loc) · 1.82 KB

README.md

File metadata and controls

49 lines (35 loc) · 1.82 KB

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)