Recording with the cli

In order to record http traffic, stubr can act as a proxy to dump this traffic into json stubs on your local filesystem. Recording can be started with the stubr record command. Stubs will be grouped by hosts. You can then play them back using stubr.

argaboutexamples
--portProxy port. Defaults to 3030.stubr --port 3031 or stubr -p 3031
--outputFile path where recorded stubs are stored. Default to current directory.stubr --port record-1 or stubr -o record-1

example

First, start stubr recorder on port 3030. It will act as a proxy.

stubr record -p 3030

We are going to consume a publicly available endpoint returning a list of sample users. We'll use curl to make this http call, and we will configure it to use our recorder as a proxy.

curl jsonplaceholder.typicode.com/users --proxy http://localhost:3030

You should have a stub under jsonplaceholder.typicode.com/users-*.json following the pattern {domain}/{path}-{md5-hash}.json.

NB: That way of recording is less intrusive than if you had to do it with wiremock, and you can configure. Most of the tools e.g. curl, JMeter, k6 or simply your web browser support configuring a http proxy (and more often than not, just by setting an environment variable, leaving your tests/scripts untouched).