Frontend tutorial
How to Mock a REST API for Frontend Development
Mock a REST API by agreeing on the contract, serving predictable local resources, and keeping the base URL configurable. Add stateful CRUD and query behavior only when the frontend needs them.
By Mock API Studio · Published September 17, 2026 · Updated September 17, 2026

Decide when the frontend needs a mock API
Use a mock when the production API is unavailable, unstable, costly to exercise, or missing states required by the UI. Do not use it to avoid eventual integration with the real backend.
Write the contract and endpoint map
Capture response types, paths, methods, auth, query names, and error expectations. Keep unknown decisions visible rather than letting mock behavior silently become the specification.
GET /tasks?page=1&limit=20
POST /tasks
PATCH /tasks/:id
DELETE /tasks/:idGenerate useful task data
Bind an exported Task type to /tasks, choose a repeatable seed, and generate enough records to cover multiple pages.
interface Task {
id: string;
title: string;
completed: boolean;
assigneeEmail?: string;
}Exercise stateful CRUD
Create a task, update its completion state, refresh the collection, and delete it. SQLite persistence makes the sequence behave like an application backend across requests and compatible restarts.
Add pagination and search
Configure the same query names planned for production and allowlist sortable fields. Test first, last, empty, and invalid requests.
GET /tasks?page=2&limit=10&search=review&sort=title&direction=ascSwitch the environment URL later
Use a development environment variable for localhost and a separate value for test or production. Before switching, run contract and integration tests against the real service.
const apiBaseUrl = process.env.NEXT_PUBLIC_API_URL;
const response = await fetch(`${apiBaseUrl}/tasks`);Consider honest alternatives
Handwritten mocks are fast for a single deterministic response. JSON Server is useful for a simple file-backed REST shape. A service worker can intercept browser requests. Choose Mock API Studio when typed models, cloud-managed configuration, stateful local CRUD, and behavior simulation fit the team.
| Approach | Best fit | Tradeoff |
|---|---|---|
| Handwritten fixture | One static state | Manual behavior and drift |
| JSON Server | Fast file-backed CRUD | Less contract-oriented configuration |
| Mock API Studio | Typed stateful local workflow | Requires cloud sync and CLI |
Put the first resource to work
Start with the API surface blocking the current feature, keep the contract small, and expand based on real frontend states.
Related questions
Should the mock become the final API specification?
Treat it as an executable development contract, but confirm decisions with the backend and validate the real implementation.
Keep exploring
Last updated September 17, 2026. Product behavior described here is verified against the current Mock API Studio runtime.