use it
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.
> +
> Started
args/flags/options
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.
install it
with precompiled binaries (linux & osx)
linux:
|
macos (Catalina):
NOTE: Big Sur users are recommended to install with cargo or from source
|
with cargo
from source (linux & osx)
&& && &&
then generate completion
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.
# or
recording
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
.
example
Using httpie
# you should have a stub under `jsonplaceholder.typicode.com/users-*.json`
arguments
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.
benchmark
A very simple benchmark comparing stubr to wiremock is available here