An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# vhttp

[![Go Test](https://github.com/a-poor/vhttp/actions/workflows/go-test.yml/badge.svg)](https://github.com/a-poor/vhttp/actions/workflows/go-test.yml)
[![Go Reference](https://pkg.go.dev/badge/github.com/a-poor/vhttp.svg)](https://pkg.go.dev/github.com/a-poor/vhttp)
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/a-poor/vhttp)
[![Go Report Card](https://goreportcard.com/badge/github.com/a-poor/vhttp)](https://goreportcard.com/report/github.com/a-poor/vhttp)
[![Coverage Status](https://coveralls.io/repos/github/a-poor/vhttp/badge.svg?branch=main)](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`)