Skip to main content

Crate mockserver_client

Crate mockserver_client 

Source
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§

BinaryResponse
Builder for a raw binary response action.
ChaosExperiment
A scheduled multi-stage chaos experiment definition. Maps to the ChaosExperiment schema (the body of PUT /mockserver/chaosExperiment).
ChaosStage
A single stage of a chaos experiment. Maps to a ChaosExperiment.stages[] entry.
ClientBuilder
Builder for constructing a MockServerClient.
CrossProtocolScenario
A cross-protocol scenario correlation: when a protocol event matching trigger (and optionally match_pattern) is observed, the named scenario is advanced to target_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.
ForwardChainExpectation
Fluent builder for creating an expectation via client.when(...).respond(...).
GrpcMethod
A single gRPC method registered from an uploaded descriptor set.
GrpcService
A gRPC service registered from an uploaded descriptor set.
GrpcStreamMessage
A single gRPC stream message in a GrpcStreamResponse.
GrpcStreamResponse
Builder for a gRPC streaming response action.
HttpChaosProfile
An HTTP chaos / fault-injection profile for a host or expectation. Maps to the HttpChaosProfile schema. Captures the commonly-used fields; the model carries an extra map for any additional server-supported keys.
HttpClassCallback
Class callback action — delegates the response (or forward) to a server-side class that implements MockServer’s callback interface.
HttpError
Error action — return a connection-level error to the caller.
HttpForward
Forward action — proxy the matched request to another host.
HttpObjectCallback
Object (closure) callback action — delegates the response (or forward) to a client-side closure invoked over the callback WebSocket.
HttpRequest
Matcher for an HTTP request. Uses builder methods for fluent construction.
HttpResponse
Builder for an HTTP response action.
HttpSseResponse
Builder for a Server-Sent Events (SSE) streaming response action.
HttpTemplate
Template action — evaluate a response or forward template (Velocity, Mustache, etc.).
HttpWebSocketResponse
Builder for a WebSocket streaming response action.
LoadCapture
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 the LoadCapture schema.
LoadFeeder
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 EITHER rows (the primary form) OR data + format. Maps to the LoadFeeder schema.
LoadPacing
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 LoadPacing schema.
LoadProfile
The load profile of a load scenario: EITHER an ordered list of LoadStages run in sequence, OR a single named LoadShape that expands into stages. Maps to the LoadProfile schema.
LoadScenario
An API-driven load scenario: ordered templated steps driven at a target concurrency. Maps to the LoadScenario schema (the body of PUT /mockserver/loadScenario, which registers the scenario in the registry without running it). The unique name is the registry key used by start/stop and the per-scenario GET/DELETE endpoints.
LoadShape
A declarative named load shape that expands into ordinary LoadStages. Maps to the LoadShape schema. Only the parameters its type needs are read; the rest are ignored. Use a shape OR an explicit stages list, not both.
LoadStage
One stage of a LoadProfile: a contiguous slice of the run holding or ramping a setpoint for duration_millis. Stages run in sequence. Maps to the LoadStage schema.
LoadStep
A single templated request step in a load scenario. Maps to the LoadStep schema.
LoadThreshold
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 LoadThreshold schema.
MockServerClient
A blocking client for the MockServer control-plane REST API.
OpenApiExpectation
An OpenAPI specification import — registers matchers and example responses for the operations in an OpenAPI/Swagger spec.
PactVerification
Outcome of a Pact contract verification (PUT /mockserver/pact/verify).
Ports
Port list (used by status and bind endpoints).
PreemptionRequest
Preemption simulation parameters (all fields optional). Maps to the PreemptionRequest schema (the body of PUT /mockserver/preemption).
PreemptionStatus
The current cordon/drain status of the server. Maps to the PreemptionStatus schema — the response of PUT/GET /mockserver/preemption.
Scenario
A handle for inspecting and driving a named scenario state-machine.
ScenarioState
A scenario and its current state, as returned by the scenario REST endpoints (GET /mockserver/scenario and GET /mockserver/scenario/{name}).
SloCriteria
A named set of service-level objectives over a time window. Maps to the SloCriteria schema (the body of PUT /mockserver/verifySLO).
SloObjective
A single service-level objective over the recorded SLI samples. Maps to the SloObjective schema.
SloObjectiveResult
The evaluated result of a single objective. Maps to the SloObjectiveResult schema.
SloVerdict
The overall verdict of an SLO evaluation. Maps to the SloVerdict schema — the response of PUT /mockserver/verifySLO.
SloWindow
The time window of an SLO evaluation. Maps to the SloCriteria.window object.
SocketAddress
A downstream socket address (host / port / scheme) to direct a request at.
SseEvent
A single Server-Sent Event in an HttpSseResponse.
TimeToLive
How long an expectation remains active.
Times
How many times an expectation should be matched.
Verification
A verification request sent to MockServer.
VerificationSequence
A verification sequence request.
VerificationTimes
Verification constraints — how many times a request must have been received.
WebSocketMessage
A single WebSocket message in an HttpWebSocketResponse.

Enums§

Body
Request/response body — either a plain string, a typed object, or a file reference.
ClearType
The type of data to clear from MockServer.
CrossProtocolTrigger
The protocol event that triggers a CrossProtocolScenario state transition. Maps to the trigger field.
Error
Errors returned by the MockServer client.
LoadCaptureSource
Where a LoadCapture extracts its value from. Maps to the capture source enum.
LoadComparator
How a LoadThreshold’s observed value is compared to its threshold. Maps to the threshold comparator enum.
LoadFeederFormat
The format of a LoadFeeder’s raw data. Maps to the feeder format enum.
LoadFeederStrategy
How a LoadFeeder selects a row each iteration. Maps to the feeder strategy enum.
LoadPacingMode
How a LoadPacing target iteration cycle is derived from its value. Maps to the pacing mode enum.
LoadShapeMetric
What a LoadShape drives. Maps to the LoadShapeMetric schema.
LoadShapeType
A named load shape that expands server-side into ordinary LoadStages. Maps to the LoadShapeType schema.
LoadStageType
The kind of a LoadStage.
LoadStepSelection
How each iteration of a load scenario selects which steps to run. Maps to the stepSelection enum.
LoadThresholdMetric
The per-run metric a LoadThreshold evaluates. Maps to the threshold metric enum.
MockMode
High-level operating mode for MockServer (set via PUT /mockserver/mode, read via GET /mockserver/mode).
RampCurve
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 the RampCurve schema. Only meaningful for ramp stages; ignored for holds and pauses.
ResponseMode
How MockServer selects which of an expectation’s multiple http_responses to return on each match. Maps to the responseMode field.
RetrieveFormat
The response format for retrieve calls.
RetrieveType
The type of data to retrieve from MockServer.

Type Aliases§

Result
Result type alias using Error.