Skip to content

Repository files navigation

vhttp

Go TestGo ReferenceGitHub go.mod Go versionGo Report CardCoverage 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(), // #1vhttp.BodyIsValidJSON(), // #2vhttp.HeaderContentTypeJSON(), // #3vhttp.HeaderAuthorizationMatchesBearer(), // #4vhttp.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

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages