stubr

stubr

Wiremock reimplemented in Rust


Crates.io version Download docs.rs docs Apache 2 ci coverage


Adaptation of wiremock-rs supporting existing Wiremock json stubs as input.
Aims at reaching feature parity with Wiremock and be a drop-in replacement of the latter.

usage

features

We list here all the capabilities supported by the original Wiremock and we track down which ones are implemented by stubr. For having a view of what is supported in a json stub refer to the Wiremock cheat sheet.

Global * [ ] anything related to xml * [x] start server oncustom port
Request matching * [x] body * [x] `equalToJson` * [x] `matchesJsonPath` * [x] `binaryEqualTo` * [x] method (GET, POST, ANY etc...) * [x] url * [x] `url` * [x] `urlPath` * [x] `urlPathPattern` * [x] `urlPattern` * [x] headers * [x] `equalTo` * [x] `contains` * [x] `matches` * [x] `caseInsensitive` * [x] `absent` * [ ] multivalued * [x] query parameters * [x] `equalTo` * [x] `contains` * [x] `matches` * [x] `caseInsensitive` * [x] `absent`
Stubbing * [x] `status` * [x] `headers` * [x] `bodyFileName` * [x] `jsonBody` * [x] `body`
Simulating faults * [x] `fixedDelayMilliseconds` * [x] global delay * [ ] random delay
Response templating * [x] `` * [x] `` * [x] `` * [x] `` * [x] `` * [x] `` * [ ] `` * [ ] `` * [ ] `` * [x] `` * [x] `` * [ ] `` * [ ] `` * [x] `` * [ ] Handlebars helpers * [ ] Number and assignment helpers * [ ] XPath helpers * [x] jsonPath helper * [ ] date and time helpers * [ ] Random value helper * [ ] Pick random helper * [ ] String trim helper * [ ] Base64 helper * [ ] URL encoding helper * [ ] Form helper * [ ] Regular expression extract helper * [ ] Size helper * [ ] Hostname helper * [ ] System property helper

Docker

A docker image is published here with each release.

You can play with it with the following commands:

echo "{\"request\": {\"method\": \"GET\"}, \"response\": { \"body\": \"Hello stubr\" }}" > hello.json &&
docker run -v $(pwd):/stubs -d --rm -p 8080:8080 ghcr.io/beltram/stubr:latest /stubs -p 8080 &&
http :8080

Which should output

HTTP/1.1 200 OK
content-length: 11
content-type: text/plain
date: Tue, 23 Mar 2021 13:37:41 GMT
server: stubr(0.4.0)

Hello stubr

Helm

A Helm chart is also maintained for those moments where you have to deploy mocks in a Kubernetes cluster.

You can play with it with the following commands:

Pending Helm --include-dir flag the workaround is to unpack the chart then copy stubs folder inside it.

mkdir stubs &&
echo "{\"request\": {\"method\": \"GET\"}, \"response\": { \"body\": \"Hello stubr\" }}" > stubs/hello.json &&
helm pull --repo https://beltram.github.io/stubr/ stubr --untar &&
mv stubs stubr &&
helm install hello-stubr ./stubr

For the hurry ones who also have k3d installed locally you can bootstrap a Kubernetes cluster locally and install stubr chart on it with the following command

curl https://raw.githubusercontent.com/beltram/stubr/main/charts/example/run.sh | sh

benchmark

Performance matters for stubr because it is meant to be a lighter version of Wiremock.

comparing to wiremock

A very simple benchmark comparing stubr to wiremock is available here.

cargo bench

A benchmark of stubr itself, powered by criterion is available for each release. The latest is available here. It aims at tracking down progresses/regressions made.

I’m still looking for a way to turn this into something more ergonomic, especially I’d like to provide a way to compare 2 benchmarks. Meanwhile, you can download the latest benchmark with these commands.

mkdir stubr-bench &&
curl -L https://github.com/beltram/stubr/releases/latest/download/bench.tar.gz | tar xz - -C stubr-bench

Then open ./stubr-bench/report/index.html in your browser.