You can use stubr
as a cli for serving Wiremock stubs on a local server or as proxy for recording http traffic into
json stubs.
To get a list of all available options run stubr --help
The simplest usage is for serving Wiremock stubs under a directory (or just a single file).
For example let's generate a simple stub.
bash
echo "{\"request\": {\"method\": \"GET\"}, \"response\": { \"status\": 200 }}" > hello.json
```bash stubr hello.json
- mounted "hello.json" Started stubr in 50ms on http://127.0.0.1:49604 ```
| arg | about | examples |
|-----|:-----:|:-------:|
| [dir]
| Folder containing stubs or individual stub. | stubr ./my-app-stubs
or stubr ./my-app-stubs/ping.json
|
| --root-dir
| Directory containing a mappings
folder with all stubs. Equivalent to Wiremock's one. Has precedence over [dir]
| stubr --root-dir ./my-app-stubs
|
| --port
| Server port. Defaults to random port. | stubr --port 8080
or stubr -p 8080
|
| --delay
| Global delay duration applied to all stubs (supersedes any locally defined delay). | stubr --delay 2s
or stubr -d 1m
or stubr -d 100ms
|
| --latency
| Delay added to any locally defined delay. Simulates network latency. | stubr --latency 2s
or stubr -l 1m
or stubr -l 100ms
|
| completion
| Generates & installs bash or zsh completion scripts | stubr completion bash
or stubr completion zsh
|
| --help
| Displays help. | stubr help
or stubr -h
for short help. stubr --help
for long help |
| --version
| Displays stubr
version. | stubr -V
or stubr --version
|
Also available as a crate.
bash
curl -L https://github.com/beltram/stubr/releases/latest/download/stubr-linux.tar.gz | tar xz - -C /usr/local/bin
NOTE: Big Sur users are recommended to install with cargo or from source
bash
curl -L https://github.com/beltram/stubr/releases/latest/download/stubr-macos.tar.gz | tar xz - -C /usr/local/bin
bash
cargo install stubr-cli
bash
git clone --depth 1 https://github.com/beltram/stubr.git && cd stubr && cargo build --release && mv target/release/stubr /usr/local/bin/
Completion files generation is currently supported for bash
and zsh
. Stubr cli provides a completion
command to
generate and install them in a standard location.
```bash stubr completion zsh
stubr completion bash ```
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
.
Using httpie
```bash stubr record -p 3030 http jsonplaceholder.typicode.com/users --proxy http://localhost:3030
jsonplaceholder.typicode.com/users-*.json
```
| arg | about | examples |
|-----|:-----:|:-------:|
| --port
| Proxy port. Defaults to 3030. | stubr --port 3031
or stubr -p 3031
|
| --output
| File path where recorded stubs are stored. Default to current directory. | stubr --port record-1
or stubr -o record-1
|
Also available as a crate for recording traffic in unit tests.
A very simple benchmark comparing stubr to wiremock is available here