Expand description
§mockserver-client
An idiomatic Rust client for MockServer’s control-plane REST API.
This crate provides a blocking (synchronous) client that communicates with a running MockServer instance over HTTP. It supports creating expectations, verifying requests, clearing/resetting state, and retrieving recorded data.
§Quick Start
use mockserver_client::{ClientBuilder, HttpRequest, HttpResponse};
let client = ClientBuilder::new("localhost", 1080).build().unwrap();
client.when(HttpRequest::new().method("GET").path("/hello"))
.respond(HttpResponse::new().status_code(200).body("world"))
.unwrap();
client.verify(
HttpRequest::new().path("/hello"),
mockserver_client::VerificationTimes::at_least(1),
).unwrap();
client.reset().unwrap();Re-exports§
pub use breakpoint::phase;pub use breakpoint::BreakpointMatcherRegistration;pub use breakpoint::BreakpointMatcherResponse;pub use breakpoint::BreakpointMatcherEntry;pub use breakpoint::BreakpointMatcherList;pub use breakpoint::PausedStreamFrame;pub use breakpoint::StreamFrameDecision;pub use breakpoint::WsEnvelope;pub use breakpoint::BreakpointRequestHandler;pub use breakpoint::BreakpointResponseHandler;pub use breakpoint::BreakpointStreamFrameHandler;pub use breakpoint::ObjectResponseHandler;pub use breakpoint::extract_header;pub use breakpoint::set_header;pub use breakpoint::route_request;pub use breakpoint::route_object_callback;pub use breakpoint::route_response;pub use breakpoint::route_stream_frame;
Modules§
- a2a
- Fluent builder for mocking an A2A (Agent-to-Agent) protocol server.
- breakpoint
- Breakpoint matcher registration, callback WebSocket client, and handler routing.
- launcher
- On-demand binary launcher for MockServer.
- llm
- Fluent LLM-mocking builders for the MockServer Rust client.
- mcp
- Fluent builder for mocking an MCP (Model Context Protocol) server.
Structs§
- Binary
Response - Builder for a raw binary response action.
- Capture
Rule - A capture rule (
capture) — extract a value from the matched request and bind it into scenario/template state underinto. - Chaos
Experiment - A scheduled multi-stage chaos experiment definition. Maps to the
ChaosExperimentschema (the body ofPUT /mockserver/chaosExperiment). - Chaos
Stage - A single stage of a chaos experiment. Maps to a
ChaosExperiment.stages[]entry. - Client
Builder - Builder for constructing a
MockServerClient. - Connection
Options - Connection-level options for an
HttpResponse— control content-length, chunking, keep-alive and socket-close behaviour. - Cross
Protocol Scenario - A cross-protocol scenario correlation: when a protocol event matching
trigger(and optionallymatch_pattern) is observed, the named scenario is advanced totarget_state. - Delay
- A time delay (e.g., for response delays).
- DnsRecord
- A single DNS resource record in a
DnsResponse. - DnsResponse
- Builder for a DNS response action.
- Expectation
- A full expectation combining a request matcher with an action.
- Expectation
Action - A side-effect action run before (
beforeActions) or after (afterActions) an expectation’s main action fires: an out-of-band request, or a class/object callback. - Expectation
Step - One step of a multi-step expectation (
steps) — used to script a sequence of responder/side-effect actions for a single match. - Forward
Chain Expectation - Fluent builder for creating an expectation via
client.when(...).respond(...). - Grpc
Bidi Message - A single message in a
GrpcBidiResponse(or one of its rule responses). - Grpc
Bidi Response - A gRPC bidirectional-streaming response action (
grpcBidiResponse). - Grpc
Bidi Rule - A request-keyed rule in a
GrpcBidiResponse— when an incoming message matchesmatch_json, the pairedresponsesare sent. - Grpc
Method - A single gRPC method registered from an uploaded descriptor set.
- Grpc
Service - A gRPC service registered from an uploaded descriptor set.
- Grpc
Stream Message - A single gRPC stream message in a
GrpcStreamResponse. - Grpc
Stream Response - Builder for a gRPC streaming response action.
- Http
Chaos Profile - An HTTP chaos / fault-injection profile for a host or expectation. Maps to
the
HttpChaosProfileschema. Captures the commonly-used fields; the model carries anextramap for any additional server-supported keys. - Http
Class Callback - Class callback action — delegates the response (or forward) to a server-side class that implements MockServer’s callback interface.
- Http
Error - Error action — return a connection-level error to the caller.
- Http
Forward - Forward action — proxy the matched request to another host.
- Http
Forward Validate Action - Forward action that also validates request/response against an OpenAPI spec
(serialised as
httpForwardValidateAction). - Http
Forward With Fallback - Forward action that falls back to a canned response when the upstream fails
(serialised as
httpForwardWithFallback). - Http
LlmResponse - The LLM response action (
httpLlmResponse). Only the completion, embedding, rerank, moderation and content-filter sub-objects are commonly set; each is optional and every unknown/nested field is preserved via its ownextracatch-all so full LLM configs round-trip. - Http
Object Callback - Object (closure) callback action — delegates the response (or forward) to a client-side closure invoked over the callback WebSocket.
- Http
Override Forwarded Request - Override the forwarded request and/or response (serialised as
httpOverrideForwardedRequest). - Http
Request - Matcher for an HTTP request. Uses builder methods for fluent construction.
- Http
Response - Builder for an HTTP response action.
- Http
SseResponse - Builder for a Server-Sent Events (SSE) streaming response action.
- Http
Template - Template action — evaluate a response or forward template (Velocity, Mustache, etc.).
- Http
WebSocket Response - Builder for a WebSocket streaming response action.
- Jwt
- JWT request matcher — matches a JSON Web Token carried on the request.
- LlmCompletion
- The chat/text completion of an
HttpLlmResponse. - LlmStreaming
Physics - Streaming timing model (physics) for an
LlmCompletion. - LlmTool
Call - A single tool call in an
LlmCompletion. - LlmUsage
- Token-usage accounting for an
LlmCompletion. - Load
Capture - A declarative cross-step capture / correlation rule: extracts a value from a
step’s response and binds it to a variable name a later step in the same
iteration can reference via
$iteration.captured.<name>. Best-effort. Maps to theLoadCaptureschema. - Load
Feeder - Parameterized test data (a data feeder) for a load scenario: an inline
dataset from which one row is selected per iteration and exposed to the
iteration’s templates as
$iteration.data.<column>. Supply EITHERrows(the primary form) ORdata+format. Maps to theLoadFeederschema. - Load
Pacing - Adaptive iteration pacing (think-time) for a load scenario: a target
per-virtual-user iteration cycle time. Applies only to the closed-model VU
loop. Maps to the
LoadPacingschema. - Load
Profile - The load profile of a load scenario: EITHER an ordered list of
LoadStages run in sequence, OR a single namedLoadShapethat expands into stages. Maps to theLoadProfileschema. - Load
Scenario - An API-driven load scenario: ordered templated steps driven at a target
concurrency. Maps to the
LoadScenarioschema (the body ofPUT /mockserver/loadScenario, which registers the scenario in the registry without running it). The uniquenameis the registry key used bystart/stopand the per-scenarioGET/DELETEendpoints. - Load
Shape - A declarative named load shape that expands into ordinary
LoadStages. Maps to theLoadShapeschema. Only the parameters itstypeneeds are read; the rest are ignored. Use a shape OR an explicitstageslist, not both. - Load
Stage - One stage of a
LoadProfile: a contiguous slice of the run holding or ramping a setpoint forduration_millis. Stages run in sequence. Maps to theLoadStageschema. - Load
Step - A single templated request step in a load scenario. Maps to the
LoadStepschema. - Load
Threshold - An in-run pass/fail threshold for a load scenario: a per-run metric compared
against a value. All thresholds must hold for the run verdict to be PASS
(logical AND). Maps to the
LoadThresholdschema. - Mock
Server Client - A blocking client for the MockServer control-plane REST API.
- Open
ApiExpectation - An OpenAPI specification import — registers matchers and example responses for the operations in an OpenAPI/Swagger spec.
- Pact
Verification - Outcome of a Pact contract verification (
PUT /mockserver/pact/verify). - Ports
- Port list (used by status and bind endpoints).
- Preemption
Request - Preemption simulation parameters (all fields optional). Maps to the
PreemptionRequestschema (the body ofPUT /mockserver/preemption). - Preemption
Status - The current cordon/drain status of the server. Maps to the
PreemptionStatusschema — the response ofPUT/GET /mockserver/preemption. - Rate
Limit - Declarative, protocol-agnostic rate limit / quota attached to an expectation.
- Recover
After - Circuit-breaker style policy on an
HttpResponse: fail the firstfail_timesrequests withfail_response, then serve the real response. - Scenario
- A handle for inspecting and driving a named scenario state-machine.
- Scenario
State - A scenario and its current state, as returned by the scenario REST
endpoints (
GET /mockserver/scenarioandGET /mockserver/scenario/{name}). - SloCriteria
- A named set of service-level objectives over a time window. Maps to the
SloCriteriaschema (the body ofPUT /mockserver/verifySLO). - SloObjective
- A single service-level objective over the recorded SLI samples. Maps to the
SloObjectiveschema. - SloObjective
Result - The evaluated result of a single objective. Maps to the
SloObjectiveResultschema. - SloVerdict
- The overall verdict of an SLO evaluation. Maps to the
SloVerdictschema — the response ofPUT /mockserver/verifySLO. - SloWindow
- The time window of an SLO evaluation. Maps to the
SloCriteria.windowobject. - Socket
Address - A downstream socket address (host / port / scheme) to direct a request at.
- SseEvent
- A single Server-Sent Event in an
HttpSseResponse. - Time
ToLive - How long an expectation remains active.
- Times
- How many times an expectation should be matched.
- Verification
- A verification request sent to MockServer.
- Verification
Sequence - A verification sequence request.
- Verification
Times - Verification constraints — how many times a request must have been received.
- WebSocket
Matcher - A per-incoming-frame response rule inside an
HttpWebSocketResponse::matchers. - WebSocket
Message - A single WebSocket message in an
HttpWebSocketResponse.
Enums§
- Body
- Request/response body — either a plain string, a typed object, or a file reference.
- Clear
Type - The type of data to clear from MockServer.
- Cross
Protocol Trigger - The protocol event that triggers a
CrossProtocolScenariostate transition. Maps to thetriggerfield. - Error
- Errors returned by the MockServer client.
- Load
Capture Source - Where a
LoadCaptureextracts its value from. Maps to the capturesourceenum. - Load
Comparator - How a
LoadThreshold’s observed value is compared to its threshold. Maps to the thresholdcomparatorenum. - Load
Feeder Format - The format of a
LoadFeeder’s rawdata. Maps to the feederformatenum. - Load
Feeder Strategy - How a
LoadFeederselects a row each iteration. Maps to the feederstrategyenum. - Load
Pacing Mode - How a
LoadPacingtarget iteration cycle is derived from its value. Maps to the pacingmodeenum. - Load
Shape Metric - What a
LoadShapedrives. Maps to theLoadShapeMetricschema. - Load
Shape Type - A named load shape that expands server-side into ordinary
LoadStages. Maps to theLoadShapeTypeschema. - Load
Stage Type - The kind of a
LoadStage. - Load
Step Selection - How each iteration of a load scenario selects which steps to run. Maps to
the
stepSelectionenum. - Load
Threshold Metric - The per-run metric a
LoadThresholdevaluates. Maps to the thresholdmetricenum. - Mock
Mode - High-level operating mode for MockServer (set via
PUT /mockserver/mode, read viaGET /mockserver/mode). - Parameter
Values - The value of a single key in a MockServer keyToMultiValue matcher (path parameters, and in general query-string parameters / headers).
- Ramp
Curve - The interpolation curve used to ramp a value (virtual users or arrival
rate) from a start setpoint to an end setpoint across a ramp
LoadStage. Maps to theRampCurveschema. Only meaningful for ramp stages; ignored for holds and pauses. - Response
Mode - How MockServer selects which of an expectation’s multiple
http_responsesto return on each match. Maps to theresponseModefield. - Retrieve
Format - The response format for retrieve calls.
- Retrieve
Type - The type of data to retrieve from MockServer.
Type Aliases§
- Extra
- Free-form map used as a forward-compatibility safety net on the wire types
that model MockServer actions. Any JSON field the typed model does not yet
name is captured here (via
#[serde(flatten)]) so it survives a deserialize-then-serialize round-trip instead of being silently dropped. - Result
- Result type alias using
Error.