Skip to content

Quickstart

Get your first mock API running in under 5 minutes.

The fastest way to start — add mocks directly from the command line.

Terminal window
mockd start -d

This starts mockd in the background on port 4280 (mock server) and 4290 (admin API).

Terminal window
mockd add http --path /api/hello --body '{"message": "Hello, World!"}'

Output:

Created mock: http_abc123
Type: http
Method: GET
Path: /api/hello
Status: 200
Terminal window
curl http://localhost:4280/api/hello

Response:

{"message": "Hello, World!"}
Terminal window
# POST endpoint
mockd add http -m POST --path /api/users --status 201 \
--body '{"id": 3, "message": "User created"}'
# Endpoint with delay
mockd add http --path /api/slow --delay 500 \
--body '{"message": "This took a while"}'
# List what you've created
mockd list

For version-controlled, reproducible mock setups.

Create mockd.yaml:

version: "1.0"
mocks:
- id: hello-world
name: Hello World Endpoint
type: http
enabled: true
http:
matcher:
method: GET
path: /api/hello
response:
statusCode: 200
headers:
Content-Type: application/json
body: '{"message": "Hello, World!"}'
Terminal window
mockd serve --config mockd.yaml

You should see output like:

mockd server starting...
Listening on http://localhost:4280
Admin API on http://localhost:4290
Loaded 1 mock(s) from mockd.yaml
Terminal window
curl http://localhost:4280/api/hello

Response:

{"message": "Hello, World!"}

Use mockd init to scaffold a starter configuration:

Terminal window
mockd init

This creates a mockd.yaml with example mocks you can customize. Then start with:

Terminal window
mockd serve

Expand your YAML config with a realistic REST API:

version: "1.0"
mocks:
- id: get-users
name: Get Users List
type: http
enabled: true
http:
matcher:
method: GET
path: /api/users
response:
statusCode: 200
body: |
{
"users": [
{"id": 1, "name": "Alice", "email": "alice@example.com"},
{"id": 2, "name": "Bob", "email": "bob@example.com"}
]
}
- id: get-user-by-id
name: Get User by ID
type: http
enabled: true
http:
matcher:
method: GET
path: /api/users/{id}
response:
statusCode: 200
body: |
{"id": "{{request.pathParam.id}}", "name": "Dynamic User"}
- id: create-user
name: Create New User
type: http
enabled: true
http:
matcher:
method: POST
path: /api/users
response:
statusCode: 201
body: '{"id": 3, "message": "User created"}'

Restart the server (Ctrl+C to stop, then start again):

Terminal window
mockd serve --config mockd.yaml

Test the endpoints:

Terminal window
# List users
curl http://localhost:4280/api/users
# Get single user (dynamic path parameter)
curl http://localhost:4280/api/users/42
# Create user
curl -X POST http://localhost:4280/api/users

Match dynamic path segments:

http:
matcher:
method: GET
path: /api/users/{id}
response:
statusCode: 200
body: '{"id": "{{request.pathParam.id}}", "name": "User {{request.pathParam.id}}"}'

This matches /api/users/1, /api/users/abc, etc.


Simulate network latency:

http:
matcher:
method: GET
path: /api/slow
response:
statusCode: 200
delayMs: 500
body: '{"message": "This took a while"}'

Use a different port:

Terminal window
mockd serve --config mockd.yaml --port 3000

mockd isn’t just for HTTP. Add other protocol mocks to the same config:

version: "1.0"
mocks:
# HTTP mock
- id: api-hello
type: http
http:
matcher: { method: GET, path: /api/hello }
response: { statusCode: 200, body: '{"msg": "hello"}' }
# WebSocket mock
- id: ws-echo
type: websocket
websocket:
path: /ws
echoMode: true
# GraphQL mock
- id: graphql-api
type: graphql
graphql:
path: /graphql
schema: |
type Query { hello: String }
resolvers:
Query.hello:
response: "world"
Terminal window
# Start everything
mockd serve --config mockd.yaml
# Test HTTP
curl http://localhost:4280/api/hello
# Test GraphQL
curl -X POST http://localhost:4280/graphql \
-H "Content-Type: application/json" \
-d '{"query": "{ hello }"}'