API Response Mocker
Set a mock response's status, headers, JSON body and delay, then copy it as a fetch() mock, MSW handler, Express route, curl command or Python mock.
API Response Mocker
Response builder
Headers
Generated code
// Mock fetch function for testing
const mockFetch = async (url, options) => {
// Simulate network delay
// No delay configured
return {
ok: true,
status: 200,
statusText: "OK",
headers: new Headers({
"Content-Type": "application/json"
}),
json: async () => ({
"success": true,
"data": {
"id": 123,
"name": "Example User",
"email": "user@example.com"
}
}),
};
};
// Usage
const response = await mockFetch("/api/endpoint");
const data = await response.json();
console.log(data);How to use
Define your mock API response with status code, headers, JSON body, and optional delay.
Get instant code snippets for fetch mocks, MSW handlers, Express routes, curl commands, and Python tests.
Copy the generated code directly into your tests or development environment. No server required.
Updated . Provided as is. Check the output before you rely on it in production.
How to use API Response Mocker
- 1
Start from a preset
Load Success (200), Created (201), Not Found (404), Server Error (500), Paginated List or Auth Error, or build a response from scratch.
- 2
Shape the response
Set the status code, add headers, write the JSON body, and add a simulated delay to test loading states.
- 3
Pick a code format
Generate the mock as JavaScript fetch, MSW, Express, cURL or Python.
- 4
Use it in your tests
Paste the MSW handler into your test setup, intercept the call in Cypress or Playwright with the JSON body, or run the Express route as a local mock server.
Questions and answers
What is API Response Mocker?
Does API Response Mocker store or send my data?
What mock code formats does API Response Mocker support?
Use it as an API
API Response Mocker is also callable as a free HTTP JSON API at
https://aidevhub.io/api/api-response-mocker/ — GET with query
parameters or POST with a JSON body, no authentication, CORS enabled, fair use
(abusive traffic is throttled at the edge; there is no per-request quota header). Responses return
{ ok, tool, result, meta }.
curl -s "https://aidevhub.io/api/api-response-mocker/?status=404&lang=fetch"
Machine-readable contract: /api/tool/api-response-mocker.json All API endpoints: /agents/ LLM site index: /llms.txt
For AI agents: how to call this tool
Machine-readable contract, endpoints and examples. Humans can ignore this section.
Best Path For Builders
Dedicated API endpoint
Deterministic outputs, machine-safe contracts, and production-ready examples.
Dedicated API
https://aidevhub.io/api/api-response-mocker/ OpenAPI: https://aidevhub.io/api/openapi.yaml