Mock API Generator
Sketch response shapes for frontend work. Mocks accelerate UI; they do not replace contract tests.
Endpoint Preview
/api/users→200Integration Code
const express = require("express");
const app = express();
app.get("/api/users", (req, res) => {
res.status(200).json([
{
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"role": "admin"
},
{
"id": 2,
"name": "Jane Smith",
"email": "jane@example.com",
"role": "user"
},
{
"id": 3,
"name": "Bob Wilson",
"email": "bob@example.com",
"role": "user"
}
]);
});
app.listen(3001, () => console.log("Mock server running on http://localhost:3001"));import { http, HttpResponse, delay } from "msw";
export const handlers = [
http.get("/api/users", async () => {
return HttpResponse.json([
{
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"role": "admin"
},
{
"id": 2,
"name": "Jane Smith",
"email": "jane@example.com",
"role": "user"
},
{
"id": 3,
"name": "Bob Wilson",
"email": "bob@example.com",
"role": "user"
}
], {
status: 200,
});
}),
];// app/api/mock/users/route.ts
import { NextResponse } from "next/server";
export async function GET() {
return NextResponse.json([
{
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"role": "admin"
},
{
"id": 2,
"name": "Jane Smith",
"email": "jane@example.com",
"role": "user"
},
{
"id": 3,
"name": "Bob Wilson",
"email": "bob@example.com",
"role": "user"
}
], {
status: 200,
});
}Mocks as temporary contracts
Frontend work often blocks on unfinished backends. A mock payload freezes a shape so UI, loading states, and error empty-states can ship in parallel. The risk is that the mock becomes truth while the API evolves — keep a single sample next to the OpenAPI/schema when you have one.
GET /api/users/1 → 200
{
"id": "usr_01",
"name": "Ada Lovelace",
"email": "ada@example.com",
"roles": ["editor"]
}
// Useful UI states to mock explicitly:
// 401 unauthorized, 404 missing, 500 upstream, slow 200What generated mocks will not teach you
Generated lists look realistic but rarely encode authorization scopes, soft-deleted rows, or partial responses. Add those cases by hand. When the real API lands, diff a production-like fixture against the mock with the JSON Diff tool.
Frequently Asked Questions
Will this host a real HTTP endpoint?
This tool helps you design mock payloads and shapes in the browser. Wiring them into MSW, json-server, or a stub server is still your project setup.
What do mocks fail to catch?
Auth edge cases, pagination quirks, eventual consistency, rate limits, and schema drift when the real API adds fields. Treat mocks as a UI accelerator, not a contract test suite.
Should mock IDs be random every refresh?
Stable IDs help Storybook and screenshot tests. Randomize only when you are stress-testing list virtualization or uniqueness handling.