api-response-mocker
A mock API response is a fake HTTP response β status code, headers, body β for testing client-side code without a real backend. Useful for testing error handling (404, 500), edge cases (slow responses, malformed JSON), and offline development. The ZTools API Response Mocker builds the response shape, exports as msw / json-server / mirage / custom-fetch handler config, or runs in-browser as a service worker that intercepts matching URLs.
Use casesβ
Test error handlingβ
Backend won't reliably return 500. Mock response forces a 500; verify your error UI renders correctly.
Develop offline against API contractβ
Backend not ready. Mock the contract; build the UI; swap in real backend later.
Test slow / timeout scenariosβ
Add a 5-second delay to a mock response; verify the loading spinner shows.
Edge-case test dataβ
Empty arrays, null fields, missing keys β manually craft each scenario.
How it worksβ
- Define request match β URL pattern (regex or wildcard) + HTTP method.
- Define response β Status code, headers, body (JSON / text). Optional delay.
- Pick output format β msw handler, json-server route, mirage route, fetch interceptor.
- Apply β Copy into your dev setup. Subsequent matching requests use the mock.
Examplesβ
Input: GET /api/users β 200 with [{id:1,name:"Alice"}]
Output: msw handler ready to copy.
Input: POST /api/login β 401 with {error: "Invalid credentials"}
Output: Triggers the failure UI in your app.
Input: GET /api/slow β 200 with 5s delay
Output: Tests loading-state UX.
Frequently asked questionsβ
Mock for production?
No β mocks are for development and testing. Production should hit real APIs.
How is this different from Mock API generator?
Mock API generator builds the response payload (the data). Response mocker builds the full HTTP response (status / headers / body / timing). Use both together.
Privacy?
All in browser.
Tipsβ
- For new projects, write the mocks before the backend β drives clear API contracts.
- Test error paths first β most apps under-test error handling.
- Use msw β service-worker-based, works for both fetch and XHR, no backend needed.
Try it nowβ
The full api-response-mocker runs in your browser at https://ztools.zaions.com/api-response-mocker β no signup, no upload, no data leaves your device.
Last updated: 2026-05-06 Β· Author: Ahsan Mahmood Β· Edit this page on GitHub