Proxy Recording
mockd includes a MITM (Man-in-the-Middle) forward proxy that records real API traffic. Configure your HTTP client to route through the proxy, and mockd captures every request/response pair to disk. You can then convert recordings into mock definitions with mockd convert.
Overview
Section titled “Overview”Proxy recording is useful for:
- Capturing real API behavior without writing mocks by hand
- Recording integration test fixtures from live services
- Creating realistic mocks from actual API responses
- Debugging API interactions by inspecting traffic
Quick Start
Section titled “Quick Start”Start the proxy in the foreground:
mockd proxy startThis starts a forward proxy on port 8888 in record mode. Configure your HTTP client to use it:
# cURL with proxycurl -x http://localhost:8888 http://api.example.com/users
# Or set environment variablesexport http_proxy=http://localhost:8888export https_proxy=http://localhost:8888curl http://api.example.com/usersThe request and response are recorded to disk. Press Ctrl+C to stop the proxy.
View what was captured:
mockd recordings listConvert recordings to mock definitions:
mockd convert -o mocks.yamlStarting the Proxy
Section titled “Starting the Proxy”The proxy runs in the foreground and stops with Ctrl+C:
# Default: port 8888, record modemockd proxy start
# Custom portmockd proxy start --port 9090
# Named session (for organizing recordings)mockd proxy start --session my-api-test
# Passthrough mode (no recording, just forwarding)mockd proxy start --mode passthrough| Flag | Short | Default | Description |
|---|---|---|---|
--port | -p | 8888 | Proxy server port |
--mode | -m | record | Proxy mode: record or passthrough |
--session | -s | default | Recording session name |
--recordings-dir | (platform default) | Base directory for recordings | |
--ca-path | CA certificate directory (enables HTTPS interception) | ||
--include | Comma-separated path patterns to include (glob) | ||
--exclude | Comma-separated path patterns to exclude (glob) | ||
--include-hosts | Comma-separated host patterns to include | ||
--exclude-hosts | Comma-separated host patterns to exclude |
Proxy Modes
Section titled “Proxy Modes”Record Mode (default)
Section titled “Record Mode (default)”Records all traffic passing through:
mockd proxy start --mode recordEvery HTTP request/response pair is persisted to disk as it flows through the proxy.
Passthrough Mode
Section titled “Passthrough Mode”Forwards traffic without recording:
mockd proxy start --mode passthroughUseful for debugging or when you only need the proxy behavior without capturing data.
HTTPS Interception
Section titled “HTTPS Interception”By default, HTTPS requests are tunneled (TCP pass-through) and not recorded because the traffic is encrypted.
To record HTTPS traffic, generate a CA certificate and configure your system to trust it:
Generate a CA Certificate
Section titled “Generate a CA Certificate”# Generate CA cert and keymockd proxy ca generate --ca-path ./certs
# Start proxy with HTTPS interceptionmockd proxy start --ca-path ./certsThe proxy dynamically generates per-host TLS certificates signed by your CA, enabling it to decrypt and record HTTPS traffic.
Trust the CA Certificate
Section titled “Trust the CA Certificate”Export the certificate for installation:
# Export to filemockd proxy ca export --ca-path ./certs -o mockd-ca.crt
# macOS: Add to system keychainsudo security add-trusted-cert -d -r trustRoot \ -k /Library/Keychains/System.keychain mockd-ca.crt
# Linux (Debian/Ubuntu): Add to system certificatessudo cp mockd-ca.crt /usr/local/share/ca-certificates/sudo update-ca-certificatesFiltering
Section titled “Filtering”Control what gets recorded using include/exclude patterns with glob matching (* wildcard):
Filter by Path
Section titled “Filter by Path”# Only record API pathsmockd proxy start --include "/api/*"
# Exclude health checksmockd proxy start --exclude "/health,/metrics,/ping"Filter by Host
Section titled “Filter by Host”# Only record traffic to specific hostsmockd proxy start --include-hosts "api.example.com,auth.example.com"
# Exclude noisy hostsmockd proxy start --exclude-hosts "analytics.example.com,cdn.example.com"Combine Filters
Section titled “Combine Filters”mockd proxy start \ --include-hosts "api.example.com" \ --include "/api/*" \ --exclude "/api/health"Filter precedence:
- If the request matches any exclude pattern → not recorded
- If include patterns exist and the request matches none → not recorded
- Otherwise → recorded
Recording Storage
Section titled “Recording Storage”Recordings are organized by session and host:
~/.local/share/mockd/recordings/├── default-20260224-143000/│ ├── meta.json│ ├── api.example.com/│ │ ├── rec_a1b2c3d4.json│ │ └── rec_e5f6a7b8.json│ └── auth.example.com/│ └── rec_c9d0e1f2.json├── my-session-20260225-091500/│ ├── meta.json│ └── ...└── latest -> default-20260224-143000/The latest symlink always points to the most recent session. The default storage location is platform-specific:
| Platform | Default Path |
|---|---|
| macOS | ~/Library/Application Support/mockd/recordings/ |
| Linux | ~/.local/share/mockd/recordings/ |
| Windows | %LOCALAPPDATA%/mockd/recordings/ |
Override with --recordings-dir or the XDG_DATA_HOME environment variable.
Managing Recordings
Section titled “Managing Recordings”List Sessions
Section titled “List Sessions”mockd recordings sessionsList Recordings
Section titled “List Recordings”# From the latest sessionmockd recordings list
# From a specific sessionmockd recordings list --session my-api-test
# Filter by method or hostmockd recordings list --method GETmockd recordings list --host api.example.comExport Recordings
Section titled “Export Recordings”# Export to JSONmockd recordings export -o recordings.json
# From a specific sessionmockd recordings export --session my-api-test -o recordings.jsonImport Recordings
Section titled “Import Recordings”mockd recordings import --input recordings.json --session importedClear Recordings
Section titled “Clear Recordings”# Clear a specific sessionmockd recordings clear --session my-api-test --force
# Clear all sessionsmockd recordings clear --forceConverting to Mocks
Section titled “Converting to Mocks”The mockd convert command transforms recorded traffic into mock definitions:
# Convert latest session, output to stdoutmockd convert
# Save to filemockd convert -o mocks.yaml
# Convert a specific sessionmockd convert --session my-api-test -o mocks.yamlSmart Matching
Section titled “Smart Matching”Detect dynamic path segments and convert them to path parameters:
# Turns /users/123 into /users/{id}mockd convert --smart-match -o mocks.yamlFiltering During Conversion
Section titled “Filtering During Conversion”# Only GET and POST requestsmockd convert --method GET,POST
# Only successful responsesmockd convert --status 2xx
# Only specific hostsmockd convert --include-hosts "api.example.com"
# Only specific pathsmockd convert --path-filter "/api/*"Duplicate Handling
Section titled “Duplicate Handling”When multiple recordings match the same endpoint:
# Keep first occurrence (default)mockd convert --duplicates first
# Keep last occurrencemockd convert --duplicates last
# Keep all occurrencesmockd convert --duplicates allExample Workflow
Section titled “Example Workflow”1. Record Real API Traffic
Section titled “1. Record Real API Traffic”# Start the proxymockd proxy start --session api-capture --port 8888
# In another terminal, run your app through the proxyhttp_proxy=http://localhost:8888 npm test
# Stop the proxy with Ctrl+C2. Review Recordings
Section titled “2. Review Recordings”mockd recordings list --session api-capture# ID METHOD HOST PATH STATUS DURATION# a1b2c3d4 GET api.example.com /api/users 200 150ms# e5f6a7b8 POST api.example.com /api/users 201 89ms# c9d0e1f2 GET api.example.com /api/users/1 200 45ms3. Convert to Mocks
Section titled “3. Convert to Mocks”mockd convert --session api-capture --smart-match -o mocks.yaml4. Use the Mocks
Section titled “4. Use the Mocks”mockd serve --config mocks.yaml# Your tests now run against captured responses — no external dependency neededProxy vs Mock Server
Section titled “Proxy vs Mock Server”| Feature | Proxy Recording | Mock Server |
|---|---|---|
| Upstream dependency | Required (for recording) | Not needed |
| Real responses | Yes | No (mocked) |
| Recording | Built-in | N/A |
| Offline operation | No | Yes |
| Best for | Capturing real behavior | Development and testing |
Next Steps
Section titled “Next Steps”- TLS/HTTPS Configuration — Certificate management for mock serving
- CLI Reference — All available commands
- Configuration Reference — Full config schema