https://github.com/aereal/go-http-replay
Record and replay HTTP response for testing
https://github.com/aereal/go-http-replay
go golang testing
Last synced: 12 months ago
JSON representation
Record and replay HTTP response for testing
- Host: GitHub
- URL: https://github.com/aereal/go-http-replay
- Owner: aereal
- License: mit
- Created: 2018-12-26T14:47:52.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2025-06-27T02:56:39.000Z (12 months ago)
- Last Synced: 2025-07-06T11:56:52.482Z (12 months ago)
- Topics: go, golang, testing
- Language: Go
- Homepage:
- Size: 50.8 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status][ci-status-badge]][ci-status]
[][license]
[![GoDoc][godoc-badge]][godoc]
# go-http-replay
Record and replay HTTP response for testing
## Synopsis
Replay HTTP response or fetch from the remote:
```go
import (
"net/http"
"testing"
httpreplay "github.com/aereal/go-http-replay"
)
func Test_http_lib(t *testing.T) {
httpClient := &http.Client{
Transport: httpreplay.NewReplayOrFetchTransport("./testdata", http.DefaultClient),
}
// httpClient will behave like the client that created from NewReplayTransport but DO actual request if local cache is missing.
}
```
Only replay HTTP response from cache:
```go
import (
"net/http"
"testing"
httpreplay "github.com/aereal/go-http-replay"
)
func Test_http_lib(t *testing.T) {
httpClient := &http.Client{
Transport: httpreplay.NewReplayTransport("./testdata"),
}
// httpClient will not do actual request to remote sites but returns the response from local cache files.
}
```
## See also
- https://github.com/vcr/vcr - go-http-replay is heavily inspired from this project
## Author
- aereal
[license]: https://github.com/aereal/go-http-replay/blob/main/LICENSE
[godoc]: https://pkg.go.dev/github.com/aereal/go-http-replay
[godoc-badge]: https://pkg.go.dev/badge/aereal/go-http-replay
[ci-status]: https://github.com/aereal/go-http-replay/actions/workflows/CI
[ci-status-badge]: https://github.com/aereal/go-http-replay/workflows/CI/badge.svg