API Response Mocker
Design mock API endpoint responses in JSON. Pick a status code, select a template,
customize the body, and get ready-to-copy mock code for
page.route(),
MSW, or plain
fetch mocking.
Endpoint Config
Response Body (JSON)
Code Snippet
Response Preview
Frequently Asked Questions
What is API response mocking and why is it useful?▼
API response mocking means creating fake API responses that look exactly like real ones, allowing you to develop and test UI components without a running backend. It's useful for: (1) frontend development before the API is ready, (2) testing error states and edge cases that are hard to trigger in real APIs, (3) CI/CD testing without external dependencies, (4) demoing features without live data.
How do I use the generated mock response in Playwright tests?▼
Use page.route() to intercept requests: await page.route('**/api/users', route => route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(yourMockData) })). Set up the route before page.goto(). You can also use route.abort() to simulate network failures or route.continue() to pass through to the real API selectively.
How do I use this with MSW (Mock Service Worker)?▼
Copy the generated response body and use it in your MSW handler: import { http, HttpResponse } from 'msw'; export const handlers = [http.get('/api/users', () => HttpResponse.json(yourMockData))]. MSW intercepts at the service worker level, working for both unit tests (with msw/node) and browser testing. It's the recommended approach for React/Next.js projects.
What HTTP status codes should I mock for error testing?▼
Critical error scenarios to mock: 400 Bad Request (validation errors), 401 Unauthorized (expired/missing token), 403 Forbidden (insufficient permissions), 404 Not Found (resource missing), 409 Conflict (duplicate resource), 422 Unprocessable Entity (business logic error), 429 Too Many Requests (rate limiting), 500 Internal Server Error (unexpected backend failure), 503 Service Unavailable (backend down). Each should return a consistent error envelope your frontend can handle.
What is a standard API response envelope?▼
An API envelope wraps your data in a consistent structure: { success: true, data: {...}, meta: { page, total } } for success responses, and { success: false, error: { code, message, details } } for errors. Using a consistent envelope means your frontend only needs one error-handling pattern regardless of the endpoint. This tool generates responses following this convention.
How do I simulate pagination in mock responses?▼
Include a meta object with page, perPage, total, and totalPages fields. For a paginated list: { data: [...items], meta: { page: 1, perPage: 20, total: 150, totalPages: 8, hasNextPage: true } }. In your Playwright or MSW setup, you can parameterize the handler to return different pages based on query params: const page = parseInt(url.searchParams.get('page') || '1').
Related Products
on GumroadDevToolkit Starter Kit
A ready-to-deploy developer tools website with 12 built-in tools. Astro + Preact + Tailwind. Deploy to Cloudflare Pages for free. Built-in SEO, dark mode, and ad-ready layout.
Buy on Gumroad →TypeScript Quick Reference Toolkit
5 practical reference files for TypeScript developers: cheatsheet, TS vs JS comparison, 20 utility types with real examples, tsconfig best practices template, and 15 common mistakes guide. Print it. Keep it on your desk.
Buy on Gumroad →Developer Productivity Bundle
Stop rebuilding the same setup every project. 51 VSCode snippets, 40 Git aliases, 5 Docker Compose stacks, 5 GitHub Actions workflows, 5 README templates, and a dotfiles kit. Set up a professional dev environment in under an hour.
Buy on Gumroad →You Might Also Need
OpenAPI Validator
Paste your OpenAPI 3.x spec (YAML or JSON) to validate structure, find missing required fields, detect duplicate paths, check for missing operationIds, and get errors and warnings with path references.
Open free tool →
API Response Mock Generator
Generate realistic mock API responses with custom status codes, headers, and JSON body. Quick templates for 200, 401, 404, 429, 500 and more. Runs in your browser.
Open free tool →
HTTP Mock Response Builder
Build mock HTTP responses for testing. Set status code, headers, and body — generate curl commands, Jest fetch mocks, and MSW v2 handlers. Runs in your browser.
Open free tool →
More Free Tools
Related Articles
MSW 2.0: The Best Way to Mock APIs in Frontend Tests
A complete guide to Mock Service Worker (MSW) 2.0 — setup, request handlers, Vitest and Jest integration, Storybook mocking, and best practices for realistic API mocking in frontend tests.
API Mocking for Frontend Development: Complete Guide (2025)
How to use API mocking to develop frontend apps without a real backend. Covers MSW, JSON Server, mock services in Postman, browser-based mock APIs, and testing strategies.
API Testing Best Practices 2026: Postman vs Insomnia vs Bruno
Complete guide to API testing in 2026. Compare Postman, Insomnia, and Bruno, learn best practices for REST and GraphQL testing, and build automation pipelines that catch regressions before production.
End-to-End Testing in 2026: Writing Tests That Don't Lie
E2E testing guide 2026: choose Playwright or Cypress, eliminate flakiness, structure test suites for CI/CD, and understand real application quality limits.
Playwright vs Selenium 2026: Which Should You Choose?
Complete comparison of Playwright and Selenium for browser automation and end-to-end testing in 2026. Performance benchmarks, API differences, migration guide, and when to use each.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$9/mo after trial · Cancel anytime
Want the full toolkit?
Get DevPlaybook Pro
Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →