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§
- Binary
Response - Builder for a raw binary response action.
- 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. - 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.
- Forward
Chain Expectation - Fluent builder for creating an expectation via
client.when(...).respond(...). - 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
Object Callback - Object (closure) callback action — delegates the response (or forward) to a client-side closure invoked over the callback WebSocket.
- 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.
- Load
Profile - The load profile of a load scenario: an ordered list of
LoadStages run in sequence. 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
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. - 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.
- 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. - 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
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
Stage Type - The kind of a
LoadStage. - 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.