Skip to content

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

Quick presets:

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

Build response

Define your mock API response with status code, headers, JSON body, and optional delay.

Generate code

Get instant code snippets for fetch mocks, MSW handlers, Express routes, curl commands, and Python tests.

Test anywhere

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

    Shape the response

    Set the status code, add headers, write the JSON body, and add a simulated delay to test loading states.

  3. 3

    Pick a code format

    Generate the mock as JavaScript fetch, MSW, Express, cURL or Python.

  4. 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?
A mock API response is a canned HTTP reply (status, headers and body) that stands in for a real backend during tests. Set those parts here, or start from presets such as 404, server error or a paginated list, and the tool writes matching code for fetch, MSW, Express, curl and Python.
Does API Response Mocker store or send my data?
No. All processing happens entirely in your browser. Your API definitions stay on your device — nothing is sent to any server.
What mock code formats does API Response Mocker support?
It generates code for JavaScript fetch, MSW (Mock Service Worker), Express.js routes, cURL commands, and Python. Each output is ready to paste directly into your project or terminal.

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

GET /api/api-response-mocker/ GET api-response-mocker
POST /api/api-response-mocker/ POST api-response-mocker