https://github.com/a-poor/vhttp
A library for testing Go HTTP requests and responses from the net/http package.
https://github.com/a-poor/vhttp
go hacktoberfest http testing
Last synced: 11 months ago
JSON representation
A library for testing Go HTTP requests and responses from the net/http package.
- Host: GitHub
- URL: https://github.com/a-poor/vhttp
- Owner: a-poor
- License: mit
- Created: 2022-08-11T14:33:41.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-28T00:30:55.000Z (almost 3 years ago)
- Last Synced: 2025-03-26T06:36:00.234Z (11 months ago)
- Topics: go, hacktoberfest, http, testing
- Language: Go
- Homepage: https://pkg.go.dev/github.com/a-poor/vhttp
- Size: 41 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# vhttp
[](https://github.com/a-poor/vhttp/actions/workflows/go-test.yml)
[](https://pkg.go.dev/github.com/a-poor/vhttp)

[](https://goreportcard.com/report/github.com/a-poor/vhttp)
[](https://coveralls.io/github/a-poor/vhttp?branch=main)
_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"
```go
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](https://pkg.go.dev/github.com/a-poor/vhttp)!
## License
`vhttp` is released under an [MIT license](./LICENSE.txt).
## Contributing
Contributions are welcome!
Please feel free to submit an issue or a PR. Or you can reach out to me on [mastodon](https://mastodon.social/@austinpoor).
## To-Do
- Add more tests!
- Add more examples!
- Form validators
- Check for `nil` pointers? (eg `*url.URL`)