API Response Mocker
Response Builder
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,
"message": "Hello World"
},
};
};
// 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.
What This Tool Does
API Response Mocker is built for deterministic developer and agent workflows.
Generate mock API responses for testing. Get instant code snippets for fetch, MSW, Express, curl, and Python. Perfect for building agent tools without spinning up a server.
Use How to Use for execution steps and FAQ for constraints, policies, and edge cases.
Last updated:
This tool is provided as-is for convenience. Output should be verified before use in any production or critical context.
Agent Invocation
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
Unified Runtime API
https://aidevhub.io/api/tools/run/?toolId=api-response-mocker&a=...
GET and POST are supported at /api/tools/run/ with identical validation and limits.
Limit: req / s, input max 128 KB.
How to Use API Response Mocker
- 1
Generate mock API responses for frontend testing
Define endpoint path, HTTP method, and shape (e.g., { id, name, email, created_at }). The tool generates realistic mock data (UUIDs for IDs, faker names/emails). Use in Storybook or Jest tests.
- 2
Create paginated response mocks for list endpoints
Configure mock for GET /users with 50 items per page. Set 'is_paginated' and specify page count. Generate paginated responses for testing pagination UI without hitting a real API.
- 3
Mock error responses for failure scenarios
Create 400, 401, 403, 500 responses with realistic error messages. Test error handling in your app without breaking the real API. Useful for negative test cases.
- 4
Use mocked responses in Cypress/Playwright tests
Generate mock response JSON, intercept the actual API call in your test (cy.intercept or page.route), and return the mocked data. App thinks it got real data, tests run fast and deterministic.
- 5
Export mock data as JSON seed files
Generate multiple mock records (e.g., 10 users), export as JSON, save to fixtures/users.json. Seed your test database or Storybook data with consistent, realistic mock data.