created by Austin Poor
A library for validating HTTP requests and responses from the net/http
package.
The following is a quick example testing that req
(of type *http.Request
)...
- Is a "GET" request
- Calling
json.Valid()
on the body returns true - Has the header "Content-Type" and it's equal to "application/json"
- The header "Authorization" matches the regular expression
^Bearer . $
- 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!
vhttp
is released under an MIT license.
Contributions are welcome!
Please feel free to submit an issue or a PR. Or you can reach out to me on twitter.
- Add more tests!
- Add more examples!
- Form validators
- Check for
nil
pointers? (eg*url.URL
)