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

Mock API Studio dashboard for configuring TypeScript models and local mock API resources
Configure typed resources in the dashboard, then run the synchronized API locally.

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.

Text
GET /tasks?page=1&limit=20
POST /tasks
PATCH /tasks/:id
DELETE /tasks/:id

Generate useful task data

Bind an exported Task type to /tasks, choose a repeatable seed, and generate enough records to cover multiple pages.

TypeScript
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.

Switch 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.

TypeScript
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.

ApproachBest fitTradeoff
Handwritten fixtureOne static stateManual behavior and drift
JSON ServerFast file-backed CRUDLess contract-oriented configuration
Mock API StudioTyped stateful local workflowRequires 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.