Skip to content

RequestBin is a golang package for testing the outgoing http requests initiated from a function. The package creates a mock server and passes the URL to the function to be tested and then collects all the requests that the server received.

parasnarang/requestBin-1

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RequestBin

Build Status Coverage Status GoDoc

RequestBin is a package for testing the outgoing http requests initiated from a function. The package creates a mock server and passes the URL to the function to be tested and then collects all the requests that the server received.

Example

func ExampleCaptureRequests() {
	reqs := NewRequestBin(MockServerConfig{RequestTimeout: 1}).CaptureRequests(func(url string) {
		http.Post(url, "text/plain", strings.NewReader("Hello"))
		http.Post(url, "text/plain", strings.NewReader("It's me"))
	})

	fmt.Println(reqs[0].Body) // Hello
	fmt.Println(reqs[1].Body) // It's me
}

The server can be stopped after a certain amount of seconds, after a certain amount of requests, whenever it doesn't receive any new requests for a certain amount of time or any combination of the three.

API

The API is very simple and you can check it on GoDoc. Reading the tests is also a good way for understanding the API.

Usecase

For a usecase you can read my blog post about this package : http://blog.mbassem.com/2016/02/09/requestbin2/.

Notes

The name RequestBin is originally used in http://requestb.in/ which basically does the same thing but using a web interface.

Contribution

Your contributions and ideas are welcomed through issues and pull requests.

About

RequestBin is a golang package for testing the outgoing http requests initiated from a function. The package creates a mock server and passes the URL to the function to be tested and then collects all the requests that the server received.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%