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§

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.
LoadProfile
The load profile of a load scenario: an ordered list of LoadStages run in sequence. 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.
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.
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.
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.
LoadStageType
The kind of a LoadStage.
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.