Skip to content

Core Concepts

Understanding the fundamental concepts of mockd will help you create effective mocks for any scenario.

mockd is not just an HTTP mock server. It supports seven protocols from a single binary and configuration file:

ProtocolUse CaseDefault Port
HTTP/HTTPSREST APIs, webhooks, file downloads4280
GraphQLGraphQL queries, mutations, subscriptions4280 (path-based)
gRPCProtobuf-based RPC services50051
WebSocketReal-time bidirectional communication4280 (path-based)
MQTTIoT devices, sensor networks, pub/sub1883
SOAP/WSDLEnterprise XML web services4280 (path-based)
SSEServer-Sent Events, AI streaming4280 (path-based)

HTTP, GraphQL, WebSocket, SOAP, and SSE share the HTTP port (4280) and are differentiated by path or content type. gRPC and MQTT run on their own ports.

All protocols are configured in the same YAML/JSON file using the type field:

mocks:
- id: rest-api
type: http # HTTP mock
http: { ... }
- id: graphql-api
type: graphql # GraphQL mock
graphql: { ... }
- id: grpc-service
type: grpc # gRPC mock
grpc: { ... }
- id: ws-endpoint
type: websocket # WebSocket mock
websocket: { ... }
- id: mqtt-broker
type: mqtt # MQTT mock
mqtt: { ... }
- id: soap-service
type: soap # SOAP mock
soap: { ... }

A mock is a rule that defines:

  1. Request Matcher - Which incoming requests to match
  2. Response - What to send back when matched
- type: http
http:
matcher: { ... } # Which requests to match
response: { ... } # What to send back

Each mock has a type (http, graphql, grpc, websocket, mqtt, soap, oauth) and a protocol-specific block. For HTTP mocks, when a request arrives, mockd checks each mock’s matcher. The first match wins and its response is returned. Other protocols use protocol-specific matching (GraphQL operations, gRPC methods, MQTT topics, etc.).

The request matcher defines criteria for matching incoming requests:

{
"matcher": {
"method": "GET",
"path": "/api/users",
"headers": {
"Authorization": "Bearer*"
},
"queryParams": {
"page": "1"
}
}
}
FieldDescriptionMatching Type
methodHTTP method (GET, POST, etc.)Exact match
pathURL pathExact or {param} pattern
pathPatternURL path regexFull regex
headersHTTP headersExact or glob (*)
queryParamsQuery string parametersExact match
bodyContainsRequest body substringSubstring match

Paths can include dynamic segments:

"/api/users/{id}" // Matches /api/users/1, /api/users/abc
"/api/{resource}/{id}" // Matches /api/posts/123

For full regex matching, use pathPattern instead of path:

{
"pathPattern": "/api/v[0-9]+/users/.*"
}

Headers support glob patterns with *:

{
"headers": {
"Authorization": "Bearer*",
"Content-Type": "*json*"
}
}

Patterns: prefix* (starts with), *suffix (ends with), *middle* (contains).

See Request Matching Guide for complete details.

The response defines what mockd sends back:

{
"response": {
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"body": {
"message": "Success"
},
"delayMs": 100
}
}
FieldDescriptionDefault
statusCodeHTTP status code200
headersResponse headers{}
bodyResponse body (string or JSON)""
delayMsSimulated latency (milliseconds)0
seedDeterministic seed for faker/random output0 (random)

The body can be:

  • JSON object/array - Automatically serialized
  • String - Sent as-is
  • File reference - Load from file
// JSON body
"body": {"users": []}
// String body
"body": "<html>Hello</html>"
// File reference
"body": "@./responses/users.json"

Responses can use templates to include request data:

{
"response": {
"body": {
"received_id": "{{request.pathParam.id}}",
"timestamp": "{{now}}"
}
}
}
VariableDescription
request.methodHTTP method
request.pathRequest path
request.pathParam.{name}Path parameter value
request.query.{name}Query parameter value
request.header.{name}Header value
request.bodyParsed request body
nowCurrent timestamp
uuidRandom UUID

See Response Templating Guide for more.

When multiple mocks could match a request, mockd uses this priority:

  1. More specific paths win - /api/users/1 beats /api/users/{id}
  2. More matchers win - Path + headers beats path only
  3. Order in config - Earlier mocks win if priority is equal

A complete configuration file:

version: "1.0"
mocks:
- id: list-users
name: List users
type: http
http:
matcher:
method: GET
path: /api/users
response:
statusCode: 200
body: '{"users": []}'
FieldDescriptionRequired
versionConfig version ("1.0")Yes
mocksArray of mock definitionsYes
tablesNamed data stores (pure data, no routing)No
extendBindings from mocks to tablesNo
importsExternal spec imports with namespacingNo
statefulResourcesLow-level CRUD resources (prefer tables + extend)No

mockd can simulate stateful CRUD APIs where:

  • POST creates resources
  • GET retrieves resources
  • PUT/PATCH updates resources
  • DELETE removes resources

State persists across requests during the server session.

The stateful architecture uses two concepts:

  • Tables — Pure data stores that hold seed data. No routing is attached.
  • Extend bindings — Wire mock endpoints to tables with a specific action (list, get, create, update, delete, custom).
tables:
- name: users
idField: id
seedData: []
mocks:
- id: list-users
type: http
http:
matcher: { method: GET, path: /api/users }
response: { statusCode: 200 }
extend:
- mock: list-users
table: users
action: list

For quick prototyping, the CLI shortcut mockd http add --path /api/users --stateful creates a table + mocks + extend bindings in one step.

See Stateful Mocking Guide.

Workspaces provide isolated environments within a single mockd instance. Each workspace has its own:

  • Mocks — route definitions scoped to the workspace
  • Stateful resources — independent data stores per workspace
  • Request logs — traffic filtered by workspace

The default workspace (empty string) contains everything not assigned to a specific workspace. Use mockd workspace create to create isolated environments, or pass --workspace <id> to scope any CLI command.

Workspaces are useful for:

  • Running multiple API environments side-by-side (e.g., Stripe + Twilio)
  • Test isolation (each test suite gets its own workspace)
  • Team separation on shared instances

mockd can act as a proxy to record real API traffic:

Terminal window
mockd proxy start

Recorded requests become mocks automatically.

See Proxy Recording Guide.

mockd provides several interfaces for managing mocks:

  • CLI — The mockd command-line tool for creating, listing, and managing mocks from your terminal. See the CLI Reference.
  • Admin API — A RESTful HTTP API on port 4290 for runtime mock management, state control, and proxy operations. See the Admin API Reference.
  • MCP Server — A Model Context Protocol server that lets AI-powered editors (Claude Code, Cursor, Windsurf) create and manage mocks directly. See the MCP Server Guide.
  • Web Dashboard — A built-in UI served from the admin port (http://localhost:4290) for visual mock management. Available in release builds. See the Dashboard Guide.