API Mock Generator
Free web tool: API Mock Generator
Define Endpoints
| Method | Path | Status | Delay (ms) | Response Body | |
|---|---|---|---|---|---|
Generated Code
const express = require('express');
const app = express();
app.use(express.json());
app.get('/api/users', (req, res) => {
res.status(200).json([ { "id": 1, "name": "Alice" }, { "id": 2, "name": "Bob" }]);
});
app.post('/api/users', (req, res) => {
setTimeout(() => {
res.status(201).json({ "id": 3, "name": "Charlie"});
}, 100);
});
app.listen(3001, () => console.log('Mock server on :3001'));About API Mock Generator
The API Mock Server Generator lets you design a set of REST API endpoints and instantly produces ready-to-run Node.js server code for either Express or Fastify. For each endpoint you specify the HTTP method (GET, POST, PUT, PATCH, or DELETE), the URL path, the HTTP response status code, the JSON response body, and an optional delay in milliseconds to simulate network latency.
Frontend developers use this tool to unblock UI development when the real backend is not yet available. QA engineers use it to create deterministic test fixtures that always return the same response. The generated code spins up a local mock server on port 3001 using only the chosen framework as a dependency — no extra libraries required.
The tool generates clean, minimal Node.js code that you can paste directly into a project file and run with node server.js. Switching between Express and Fastify output is a single click, and adding or removing endpoints updates the generated code in real time. All code generation happens in the browser — no data is sent to any server.
Key Features
- Define multiple REST endpoints with independent method, path, status, and body
- Generate Express (CommonJS) or Fastify server code with one click
- Configurable response delay per endpoint to simulate network latency
- Supports GET, POST, PUT, PATCH, and DELETE HTTP methods
- JSON response body editor per endpoint with real-time code preview
- One-click copy of the complete server code to the clipboard
- Add or remove endpoints dynamically — code updates instantly
- 100% client-side generation — no server upload, no account required
Frequently Asked Questions
What is an API mock server?
An API mock server is a lightweight server that returns predefined responses for specific HTTP requests, simulating a real backend API. It allows frontend teams to develop and test UI components independently of the actual backend service, using controlled, predictable data.
How do I run the generated mock server?
Copy the generated code, paste it into a file (e.g., mock-server.js), then run npm install express (or fastify) and node mock-server.js in your terminal. The server will start on port 3001 and respond to the endpoints you defined.
What is the response delay setting for?
The delay field (in milliseconds) adds a setTimeout around the response, simulating network latency or slow database queries. This lets you test UI loading states, spinners, and timeout handling in your frontend code with realistic timing.
Can I define endpoints that return non-200 status codes?
Yes. Each endpoint has its own status code field. You can set 201 for POST creation responses, 404 for not-found scenarios, 401 for authentication errors, 500 for server error testing, or any other valid HTTP status code.
What is the difference between the Express and Fastify output?
Express output uses the traditional CommonJS require() style with app.get/post/etc. and res.status().json(). Fastify output uses its native reply.code().send() API with async/await. Both listen on port 3001. Choose whichever framework you prefer or already use in your project.
Can I use this for testing with tools like Jest or Cypress?
Yes. Start the generated mock server before your test suite, point your fetch/axios calls to http://localhost:3001, and your tests will receive the exact responses you configured. This gives you deterministic integration tests without network dependencies.
Does the tool support request body validation?
The generated mock server returns the configured response regardless of the request body content. It is designed for simple mocking, not full contract validation. For schema validation, consider extending the generated code with libraries like Zod or Joi.
Is the generated code production-ready?
The generated code is designed for local development and testing mocks, not production deployment. It does not include authentication, HTTPS, rate limiting, or error handling middleware. Use it as a development aid and replace it with the real backend before going to production.