Quickstart
Get your first mock API running in under 5 minutes.
Prerequisites
Section titled “Prerequisites”- mockd installed (Installation Guide)
- A terminal
- curl or any HTTP client
Option A: CLI-First (No Config File)
Section titled “Option A: CLI-First (No Config File)”The fastest way to start — add mocks directly from the command line.
Start an Empty Server
Section titled “Start an Empty Server”mockd start -dThis starts mockd in the background on port 4280 (mock server) and 4290 (admin API).
Add a Mock
Section titled “Add a Mock”mockd add http --path /api/hello --body '{"message": "Hello, World!"}'Output:
Created mock: http_abc123 Type: http Method: GET Path: /api/hello Status: 200Test It
Section titled “Test It”curl http://localhost:4280/api/helloResponse:
{"message": "Hello, World!"}Add More Mocks
Section titled “Add More Mocks”# POST endpointmockd add http -m POST --path /api/users --status 201 \ --body '{"id": 3, "message": "User created"}'
# Endpoint with delaymockd add http --path /api/slow --delay 500 \ --body '{"message": "This took a while"}'
# List what you've createdmockd listOption B: YAML Config File
Section titled “Option B: YAML Config File”For version-controlled, reproducible mock setups.
Create a Config File
Section titled “Create a Config File”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!"}'Start the Server
Section titled “Start the Server”mockd serve --config mockd.yamlYou should see output like:
mockd server starting...Listening on http://localhost:4280Admin API on http://localhost:4290Loaded 1 mock(s) from mockd.yamlTest Your Mock
Section titled “Test Your Mock”curl http://localhost:4280/api/helloResponse:
{"message": "Hello, World!"}Option C: Initialize a Project
Section titled “Option C: Initialize a Project”Use mockd init to scaffold a starter configuration:
mockd initThis creates a mockd.yaml with example mocks you can customize. Then start with:
mockd serveAdding More Mocks
Section titled “Adding More Mocks”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):
mockd serve --config mockd.yamlTest the endpoints:
# List userscurl http://localhost:4280/api/users
# Get single user (dynamic path parameter)curl http://localhost:4280/api/users/42
# Create usercurl -X POST http://localhost:4280/api/usersUsing Path Parameters
Section titled “Using Path Parameters”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.
Adding Delays
Section titled “Adding Delays”Simulate network latency:
http: matcher: method: GET path: /api/slow response: statusCode: 200 delayMs: 500 body: '{"message": "This took a while"}'Changing the Port
Section titled “Changing the Port”Use a different port:
mockd serve --config mockd.yaml --port 3000Beyond HTTP
Section titled “Beyond HTTP”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"# Start everythingmockd serve --config mockd.yaml
# Test HTTPcurl http://localhost:4280/api/hello
# Test GraphQLcurl -X POST http://localhost:4280/graphql \ -H "Content-Type: application/json" \ -d '{"query": "{ hello }"}'What’s Next?
Section titled “What’s Next?”- Core Concepts - Understand mocks, matching, and responses
- Request Matching - Advanced matching patterns
- Stateful Mocking - Simulate CRUD APIs
- Protocol Guides - GraphQL, gRPC, WebSocket, MQTT, SOAP, SSE
- CLI Reference - All command-line options