https://github.com/areknoster/hypert
Go package for rapid testing of real HTTP APIs integrations. Sanitize and record requests and responses during development. Replay and validate in CI.
https://github.com/areknoster/hypert
api api-client api-rest go golang http http-client integration-testing unit-testing
Last synced: 13 days ago
JSON representation
Go package for rapid testing of real HTTP APIs integrations. Sanitize and record requests and responses during development. Replay and validate in CI.
- Host: GitHub
- URL: https://github.com/areknoster/hypert
- Owner: areknoster
- License: mit
- Created: 2024-03-09T14:58:14.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-11-23T09:02:51.000Z (2 months ago)
- Last Synced: 2025-12-19T02:54:59.118Z (about 1 month ago)
- Topics: api, api-client, api-rest, go, golang, http, http-client, integration-testing, unit-testing
- Language: Go
- Homepage:
- Size: 98.6 KB
- Stars: 25
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Hypert - HTTP API Testing Made Easy
[![ci-img]][ci-url]
[![pkg-img]][pkg-url]
[![reportcard-img]][reportcard-url]
[![coverage-img]][coverage-url]
[![tag-img]][tag-url]
[![license-img]][license-url]
Hypert is an open-source Go library that simplifies testing of HTTP API clients. It provides a convenient way to record and replay HTTP interactions, making it easy to create reliable and maintainable tests for your API clients.
## Features
- Record and replay HTTP interactions
- Request sanitization to remove sensitive information
- Request validation to ensure the integrity of recorded requests
- Seamless integration with Go's `http.Client`
- Extensible and configurable options
## Getting Started
1. Install Hypert:
```bash
go get github.com/areknoster/hypert
```
2. Use `hypert.TestClient` to create an `http.Client` instance for testing:
```go
func TestMyAPI(t *testing.T) {
httpClient := hypert.TestClient(t, true) // true to record real requests
// Use the client to make API requests.
// The requests and responses would be stored in ./testdata/TestMyAPI
myAPI := NewMyAPI(httpClient, os.GetEnv("API_SECRET"))
// Make an API request with your adapter.
// use static arguments, so that validation against recorded requests can happen
stuff, err := myAPI.GetStuff(time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC))
if err != nil {
t.Fatalf("failed to get stuff: %v", err)
}
// Assertions on the actual API response
if stuff.ID != "ID-FROM-RESP" {
t.Errorf("stuff ")
}
}
```
After you're done with building and testing your integration, change the mode to replay
```go
func TestMyAPI(t *testing.T) {
httpClient := hypert.TestClient(t, false) // false to replay stored requests
// Now client would validate requests against what's stored in ./testdata/TestMyAPI/*.req.http
// and load the response from ./testdata/TestMyAPI/*.resp.http
myAPI := NewMyAPI(httpClient, os.GetEnv("API_SECRET"))
// HTTP requests are validated against what was prevously recorded.
// This behaviour can be customized using WithRequestValidator option
stuff, err := myAPI.GetStuff(time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC))
if err != nil {
t.Fatalf("failed to get stuff: %v", err)
}
// Same assertions that were true on actual API responses should be true for replayed API responses.
if stuff.ID != "ID-FROM-RESP" {
t.Errorf("stuff ")
}
}
```
Now your tests:
- are deterministic
- are fast
- bring the same confidence as integration tests
## Stability
I plan to maintain backward compatibility as much as possible, but breaking changes may occur before the first stable release, v1.0.0 if major issues are discovered.
## Examples
Check out the [examples](examples/) directory for sample usage of Hypert in different scenarios.
## Contributing
Contributions are welcome! If you find a bug or have a feature request, please open an issue on the [GitHub repository](https://github.com/areknoster/hypert). If you'd like to contribute code, please fork the repository and submit a pull request.
## License
Hypert is released under the [MIT License](LICENSE).
---
[ci-img]: https://github.com/areknoster/hypert/actions/workflows/ci.yaml/badge.svg
[ci-url]: https://github.com/areknoster/hypert/actions/workflows/ci.yaml
[pkg-img]: https://pkg.go.dev/badge/areknoster/hypert/
[pkg-url]: https://pkg.go.dev/github.com/areknoster/hypert/
[reportcard-img]: https://goreportcard.com/badge/github.com/areknoster/hypert
[reportcard-url]: https://goreportcard.com/report/github.com/areknoster/hypert
[coverage-img]: https://codecov.io/gh/areknoster/hypert//branch/main/graph/badge.svg
[coverage-url]: https://codecov.io/gh/areknoster/hypert/
[license-img]: https://img.shields.io/badge/License-MIT-yellow.svg
[license-url]: https://github.com/areknoster/hypert/blob/main/LICENSE
[tag-img]: https://img.shields.io/github/v/tag/areknoster/hypert
[tag-url]: https://github.com/areknoster/hypert/tags