Skip to content
A Go http://golang.org/ Http Mocking Library
Go
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
.gitignore
CHANGELOG
README.md
TODO
httpmock.go
httpmock_test.go

README.md

HttpMock

HttpMock is a mocking library for http requests. It works by overwriting the http default client so that you can provide your own responder.

Example:

var resp *http.Response
var err error

f := func() { resp, err = http.Get("http://example.com") }

responder := func(req *http.Request) (*http.Response, error) {
   if req.URL.String() == "http://example.com" {
     return &http.Response{Status: "200", Body:
     httpmock.NewBody("Hello, World!")}, nil
   }
   return nil, nil
}

httpmock.Activate(f, responder)

Status

Work in progress. Not all the api has been defined yet but it's a good starting point if you need to test http interactions.

License

MIT

Something went wrong with that request. Please try again.