--- title: crates.io description: Add the mockserver-client crate from crates.io to drive MockServer from Rust tests — fluent builder API, synchronous reqwest client, and an on-demand binary launcher. layout: page pageOrder: 6.5 section: 'Where' subsection: true sitemap: priority: 0.6 changefreq: 'monthly' lastmod: 2026-06-11T08:00:00+01:00 ---
The mockserver-client crate provides an idiomatic Rust client for MockServer's control-plane REST API. It uses a blocking reqwest client (no async runtime required) and includes an on-demand binary launcher that starts MockServer without Java or Docker.
Add to Cargo.toml. For a test-only dependency, use [dev-dependencies]:
[dev-dependencies]
mockserver-client = "7.0"
For use in non-test code, use [dependencies]:
[dependencies]
mockserver-client = "7.0"
use mockserver_client::{ClientBuilder, HttpRequest, HttpResponse, VerificationTimes};
fn main() -> mockserver_client::Result<()> {
let client = ClientBuilder::new("localhost", 1080).build()?;
// Create an expectation
client.when(HttpRequest::new().method("GET").path("/hello"))
.respond(HttpResponse::new().status_code(200).body("world"))?;
// Verify the request was received
client.verify(
HttpRequest::new().path("/hello"),
VerificationTimes::at_least(1),
)?;
// Reset
client.reset()?;
Ok(())
}
The crate includes a binary launcher — no Java installation or Docker required:
use mockserver_client::launcher;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut handle = launcher::start(1080)?;
println!("MockServer running on port {}", handle.port());
// ... use MockServer ...
handle.stop()?;
Ok(())
}
See Running MockServer — client library launcher for full launcher options (version pinning, cache directory, air-gapped networks).
For the full Rust client API, see MockServer clients.