mockserver-client
An idiomatic Rust client for MockServer's control-plane REST API.
Installation
Add to your Cargo.toml:
[]
= "7.0"
Quick Start
use ;
Features
- Fluent builder API —
client.when(request).respond(response) - Response, Forward, and Error actions — full MVP control-plane coverage
- Verification —
verify(count-based) andverify_sequence(order-based) - Retrieve — recorded requests, active expectations, recorded expectations, logs
- Clear / Reset — by request matcher, by expectation ID, or full reset
- Status / Bind — query ports, bind additional ports
- Blocking (synchronous) — uses
reqwestblocking client; no async runtime needed - TLS support — optional HTTPS with configurable certificate verification
API Overview
use *;
let client = new.build.unwrap;
// Fluent expectation creation
client.when
.times
.respond?;
// Forward action
client.when
.forward?;
// Verify
client.verify?;
// Verify sequence
client.verify_sequence?;
// Clear by request matcher
client.clear?;
// Clear by ID
client.clear_by_id?;
// Retrieve recorded requests
let requests = client.retrieve_recorded_requests?;
// Retrieve active expectations
let expectations = client.retrieve_active_expectations?;
// Server status
let ports = client.status?;
println!;
// Reset everything
client.reset?;
Interactive Breakpoints
Register breakpoint matchers to pause forwarded/proxied traffic at REQUEST, RESPONSE, RESPONSE_STREAM, or INBOUND_STREAM phases. A callback WebSocket connection is opened automatically.
use *;
let client = new.build?;
// REQUEST-only breakpoint
let id = client.add_request_breakpoint?;
// REQUEST + RESPONSE breakpoint
let id2 = client.add_request_response_breakpoint?;
// Streaming breakpoint
let id3 = client.add_stream_breakpoint?;
// Manage matchers
let list = client.list_breakpoint_matchers?;
client.remove_breakpoint_matcher?;
client.clear_breakpoint_matchers?;
client.close_breakpoint_websocket;
Stream frame decisions: StreamFrameDecision::continue_frame, ::modify, ::drop_frame, ::inject, ::close.
Start / Launch MockServer
The Rust client can download and launch a local MockServer instance directly -- no Java installation and no Docker required. The launcher downloads a self-contained platform bundle (mockserver-<version>-<os>-<arch>) from the GitHub Release, verifies its SHA-256, caches it per-user, and starts it.
Quick start
use launcher;
Just ensure the binary is present
let launcher_path = ensure_launcher?;
println!;
Specify a version
let mut handle = start_with_version?;
API reference
| Function / Type | Description |
|---|---|
launcher::ensure_launcher() |
Download, verify, cache the default-version binary, and return the launcher PathBuf. |
launcher::ensure_binary(version, opts) |
Same as above, but for a specific version. |
launcher::start(port) |
Ensure the binary and start MockServer at the default version. Returns a ServerHandle. |
launcher::start_with_version(version, port, opts) |
Start MockServer at a specific version. Returns a ServerHandle. |
launcher::ServerHandle |
Handle to the running process. Methods: stop(), wait(), port(). |
launcher::VERSION |
The default MockServer version, derived from Cargo.toml at compile time via env!("CARGO_PKG_VERSION"). |
Supported platforms
| OS | Architecture |
|---|---|
| Linux | x86_64, aarch64 |
| macOS (darwin) | x86_64, aarch64 |
| Windows | x86_64, aarch64 |
Environment variables
| Variable | Purpose |
|---|---|
MOCKSERVER_BINARY_BASE_URL |
Mirror host for the release assets (corporate / air-gapped networks) |
MOCKSERVER_BINARY_CACHE |
Override the cache directory (default: ~/.cache/mockserver/binaries on Unix) |
MOCKSERVER_SKIP_BINARY_DOWNLOAD |
Fail instead of downloading (use with a pre-seeded cache in CI) |
Version
By default the launcher downloads the MockServer version matching this crate (derived from Cargo.toml at compile time via env!("CARGO_PKG_VERSION")). Pass an explicit version to override.
Building
Integration Tests
Integration tests require a running MockServer and are skipped by default:
# Start MockServer (e.g., via Docker)
# Run integration tests
MOCKSERVER_URL=http://localhost:1080
License
Apache-2.0