Crate stubr

source · []
Expand description

This crate proposes a reimplementation of Wiremock. Its aims at converting Wiremock stubs into wiremock-rs mocks.

You can also use stubr-build to share stubs between a producer project and a consumer one.

Also available as a cli.

use it

use isahc;
use stubr::*;
use asserhttp::*;

async fn simple_async() {
    // supply a directory containing json stubs. Invalid files are just ignored
    let stubr = Stubr::start("tests/stubs").await;
    // or just mount a single file
    let stubr = Stubr::start("tests/stubs/hello.json").await;
    // or configure it (more configurations to come)
    let stubr = Stubr::start_with("tests/stubs", Config { port: Some(8080), ..Default::default () }).await;

fn simple_blocking() {
    // can also be used in a blocking way
    let stubr = Stubr::start_blocking("tests/stubs");
    let stubr = Stubr::start_blocking_with("tests/stubs", Config { port: Some(8080), ..Default::default () });


use isahc;
use stubr::*;
use asserhttp::*;

#[stubr::mock] // <- takes all stubs under "tests/stubs"
async fn with_macro() {

#[stubr::mock("pets", port = 4321)] // <- takes all stubs under "tests/stubs/pets"
async fn with_path_and_port() {


A Stubr server can be configured globally thanks to Config struct.

use stubr::Config;
let config = Config {
    // server port, defaults to random
    port: Some(8080),
    // enable verbose logs
    verbose: Some(true),
    // global delay in milliseconds. Supersedes any locally defined one.
    global_delay: Some(2000),
    // delay in milliseconds added to any locally defined one. Simulates network latencies.
    latency: Some(2000),


Stubr server configuration.

Allows running a Wiremock mock server from Wiremock stubs. Delegates runtime to wiremock-rs.

Attribute Macros

Starts a Stubr server for each remote app name supplied.

Starts a Stubr mock server and creates a stubr variable which can be used to call the server e.g. stubr.uri(). It supports both standard and async test functions.