[Feature] Add Mock Server
Labels
enhancement, mock-server, testing
Problem Statement
When developing frontend applications, developers often need to:
- Test API integrations before the backend is ready
- Simulate error responses and edge cases
- Work offline without real API access
- Create reproducible test scenarios
Currently, RestBolt can only call real APIs. A built-in mock server would let developers simulate API responses locally.
Proposed Solution
Core Features
-
Mock Response Builder
- Define mock responses for any endpoint
- Set custom status codes (200, 404, 500, etc.)
- Add custom headers
- Define response body (JSON, XML, HTML, etc.)
- Add response delay to simulate network latency
-
Mock Server Manager
- Start/stop local mock server
- Configure port (default: 3001)
- List all active mocks
- Enable/disable individual mocks
- Import/export mock configurations
-
Integration with Collections
- Turn any saved request into a mock
- One-click "Mock this response"
- Organize mocks in collections
UI Mockup
┌─────────────────────────────────────────────────┐
│ Mock Server │
│ │
│ Status: ● Running on http://localhost:3001 │
│ [Stop Server] [Settings] │
├─────────────────────────────────────────────────┤
│ │
│ Active Mocks (3): │
│ │
│ ✓ GET /api/users → 200 (50ms delay) │
│ ✓ POST /api/users → 201 │
│ ✓ GET /api/users/:id → 200 │
│ │
│ [+ New Mock] [Import] [Export] │
└─────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────┐
│ Create Mock Response │
├─────────────────────────────────────────────────┤
│ Method: [GET ▼] │
│ │
│ Path: │
│ /api/users/:id │
│ │
│ Status Code: │
│ [200 ▼] OK │
│ │
│ Response Headers: │
│ Content-Type: application/json │
│ [+ Add Header] │
│ │
│ Response Body: │
│ ┌─────────────────────────────────────────────┐│
│ │ { ││
│ │ "id": "{{userId}}", ││
│ │ "name": "John Doe", ││
│ │ "email": "john@example.com" ││
│ │ } ││
│ └─────────────────────────────────────────────┘│
│ │
│ Delay (ms): [50] │
│ │
│ [Cancel] [Create Mock] │
└─────────────────────────────────────────────────┘
Technical Architecture
// Mock definition type
interface MockResponse {
id: string;
method: string;
path: string;
pathPattern: RegExp; // For dynamic paths like /users/:id
statusCode: number;
headers: Record<string, string>;
body: string;
delay?: number; // milliseconds
enabled: boolean;
}
// Mock server service
class MockServerService {
private server: any; // Express or similar
private mocks: MockResponse[] = [];
async start(port: number = 3001) {
// Start local server
}
async stop() {
// Stop server
}
addMock(mock: MockResponse) {
// Add new mock endpoint
}
removeMock(id: string) {
// Remove mock
}
matchRequest(method: string, path: string): MockResponse | null {
// Find matching mock for incoming request
}
}
Implementation Approach
Option 1: Embedded HTTP Server (Recommended)
- Use lightweight HTTP server (e.g.,
express or fastify)
- Run in-process with Next.js app
- Simple to implement and manage
- Pros: Full control, easy debugging
- Cons: Port management
Option 2: Service Worker
- Use Service Worker API to intercept requests
- No separate server needed
- Pros: No port configuration needed
- Cons: More complex, browser-only
Option 3: Next.js API Routes
- Use Next.js built-in API routes
- Dynamic route matching
- Pros: Native to Next.js
- Cons: Requires app restart for changes
Recommendation: Start with Option 1 (embedded server) for simplicity and control.
Implementation Steps
-
Phase 1: Basic Mock Server (2-3 days)
-
Phase 2: Advanced Features (2-3 days)
-
Phase 3: Integration (1-2 days)
Libraries to Consider
express or fastify - HTTP server
path-to-regexp - Path pattern matching (for dynamic routes)
json-server - Inspiration for API design
Acceptance Criteria
Use Cases
Use Case 1: Frontend Development
Developer is building a React app but backend isn't ready yet:
- Creates mock for
GET /api/users returning user list
- Creates mock for
POST /api/users returning 201 Created
- Frontend team can develop against mocks
- Switch to real API when ready
Use Case 2: Error Testing
Developer wants to test error handling:
- Create mock for
GET /api/data with 500 status
- Add 2-second delay to simulate slow network
- Test app's error handling
- Switch back to 200 success to test happy path
Use Case 3: Demos
Developer needs to demo app without internet:
- Create mocks for all API endpoints
- Export mock configuration
- Import on demo machine
- App works offline perfectly
Priority
Medium-Low - Nice to have, but not critical for core API testing functionality
Estimated Effort
5-7 days for full implementation with advanced features
2-3 days for basic mock server only
References
[Feature] Add Mock Server
Labels
enhancement,mock-server,testingProblem Statement
When developing frontend applications, developers often need to:
Currently, RestBolt can only call real APIs. A built-in mock server would let developers simulate API responses locally.
Proposed Solution
Core Features
Mock Response Builder
Mock Server Manager
Integration with Collections
UI Mockup
Technical Architecture
Implementation Approach
Option 1: Embedded HTTP Server (Recommended)
expressorfastify)Option 2: Service Worker
Option 3: Next.js API Routes
Recommendation: Start with Option 1 (embedded server) for simplicity and control.
Implementation Steps
Phase 1: Basic Mock Server (2-3 days)
Phase 2: Advanced Features (2-3 days)
/users/:id)Phase 3: Integration (1-2 days)
Libraries to Consider
expressorfastify- HTTP serverpath-to-regexp- Path pattern matching (for dynamic routes)json-server- Inspiration for API designAcceptance Criteria
Use Cases
Use Case 1: Frontend Development
Developer is building a React app but backend isn't ready yet:
GET /api/usersreturning user listPOST /api/usersreturning 201 CreatedUse Case 2: Error Testing
Developer wants to test error handling:
GET /api/datawith 500 statusUse Case 3: Demos
Developer needs to demo app without internet:
Priority
Medium-Low - Nice to have, but not critical for core API testing functionality
Estimated Effort
5-7 days for full implementation with advanced features
2-3 days for basic mock server only
References