A flexible mock API service built with Node.js, TypeScript, and Firebase that allows you to create and manage project-based mock endpoints for development and testing purposes.
- Create and manage multiple projects
- Create custom API endpoints dynamically through API
- Support for all HTTP methods (GET, POST, PUT, DELETE, PATCH)
- Configure response data, status codes, and response delays
- CORS enabled by default
- TypeScript support
- Hot reloading during development
- Firebase Firestore persistence
- Project-based endpoint organization
src/
├── controllers/ # HTTP request handlers
│ ├── project.controller.ts
│ └── endpoint.controller.ts
├── services/ # Business logic
│ ├── firebase.service.ts
│ ├── project.service.ts
│ └── endpoint.service.ts
├── types/ # TypeScript type definitions
│ ├── index.ts
│ ├── endpoint.types.ts
│ ├── project.types.ts
│ ├── config.types.ts
│ └── error.types.ts
├── server.ts # Express application setup
└── index.ts # Application entry point
- Firebase project with Firestore enabled
- Firebase service account key (serviceAccountKey.json)
The following environment variables can be configured:
PORT: Server port (default: 3000)FIREBASE_PROJECT_ID: Your Firebase project IDFIREBASE_SERVICE_ACCOUNT_KEY_PATH: Path to your Firebase service account key file (default: ./serviceAccountKey.json)
- Install dependencies:
npm install- Place your Firebase service account key in the root directory as
serviceAccountKey.json
- Start the server:
# Development mode with hot reloading
npm run dev
# Production mode
npm start- Create a project:
curl -X POST http://localhost:3000/_mock-api/projects \
-H "Content-Type: application/json" \
-d '{
"name": "my-test-project"
}'- Create endpoints for your project:
curl -X POST http://localhost:3000/_mock-api/projects/{projectId}/endpoints \
-H "Content-Type: application/json" \
-d '{
"path": "/api/products",
"method": "GET",
"response": [
{ "id": 1, "name": "Product 1" }
],
"statusCode": 200,
"delay": 500
}'POST /_mock-api/projects
Content-Type: application/json
{
"name": "my-test-project"
}Response:
- 201: Project created successfully
- 400: Invalid project name
- 409: Project already exists
- 500: Server error
GET /_mock-api/projectsResponse:
- 200: List of projects
- 500: Server error
PATCH /_mock-api/projects/{projectId}
Content-Type: application/json
{
"name": "new-project-name"
}Response:
- 200: Updated project
- 400: Invalid update data
- 404: Project not found
- 409: New name already exists
- 500: Server error
DELETE /_mock-api/projects/{projectId}Response:
- 200: Project deleted successfully
- 404: Project not found
- 500: Server error
GET /_mock-api/projects/{projectId}/endpointsResponse:
- 200: List of endpoints
- 404: Project not found
- 500: Server error
POST /_mock-api/projects/{projectId}/endpoints
Content-Type: application/json
{
"path": "/api/products",
"method": "GET",
"response": [
{ "id": 1, "name": "Product 1" }
],
"statusCode": 200,
"delay": 500
}Response:
- 201: Endpoint created successfully
- 400: Missing required fields
- 404: Project not found
- 409: Endpoint already exists
- 500: Server error
PATCH /_mock-api/projects/{projectId}/endpoints/{endpointId}
Content-Type: application/json
{
"path": "/api/products",
"method": "GET",
"response": [
{ "id": 1, "name": "Updated Product" }
],
"statusCode": 200,
"delay": 1000
}Response:
- 200: Endpoint updated successfully
- 400: Invalid update data
- 404: Project or endpoint not found
- 500: Server error
DELETE /_mock-api/projects/{projectId}/endpoints/{endpointId}Response:
- 200: Endpoint deleted successfully
- 404: Project or endpoint not found
- 500: Server error
All endpoints are accessible under their project's namespace:
# If your project ID is "abc123" and you created an endpoint at "/api/products"
curl http://localhost:3000/abc123/api/productsEach endpoint can be configured with the following options:
path: The API endpoint path (e.g., '/api/products')method: HTTP method ('GET', 'POST', 'PUT', 'DELETE', 'PATCH')response: The response data to returnstatusCode: HTTP status code (defaults to 200)delay: Response delay in milliseconds (optional)
- Create a project:
curl -X POST http://localhost:3000/_mock-api/projects \
-H "Content-Type: application/json" \
-d '{
"name": "ecommerce-api"
}'- Create a GET endpoint:
curl -X POST http://localhost:3000/_mock-api/projects/{projectId}/endpoints \
-H "Content-Type: application/json" \
-d '{
"path": "/api/products",
"method": "GET",
"response": [
{ "id": 1, "name": "Product 1" },
{ "id": 2, "name": "Product 2" }
]
}'- Create a POST endpoint with delay:
curl -X POST http://localhost:3000/_mock-api/projects/{projectId}/endpoints \
-H "Content-Type: application/json" \
-d '{
"path": "/api/orders",
"method": "POST",
"response": { "message": "Order created", "id": 123 },
"statusCode": 201,
"delay": 1000
}'- Test your endpoints:
# Test GET endpoint
curl http://localhost:3000/{projectId}/api/products
# Test POST endpoint
curl -X POST http://localhost:3000/{projectId}/api/ordersISC