consolelog.tools

API Mock Generator

Generate MSW, json-server, Nock, Express, or fetch mocks from a JSON Schema or example — schema-aware, with an optional seed for reproducible data and a live preview.

About this ToolHow it works, benefits & use cases

The API Mock Generator turns a description of your endpoints into ready-to-run mock code for the framework you actually use. Define each endpoint with a method, path and record count, then choose how the data is shaped: Auto mode invents smart field values from the property name (an "email" field becomes a real-looking address, "createdAt" becomes an ISO date, "id" becomes a number), or you can drive generation from a JSON Schema (honouring type, enum, format, minimum/maximum and minItems/maxItems) or from a single JSON example whose shape is inferred and repeated. Export the result as MSW handlers, a json-server db.json, Nock interceptors, an Express server, a drop-in window.fetch mock, or raw JSON. Set a seed for byte-for-byte reproducible data, or leave it blank for fresh records each run. Everything previews live and runs entirely in the browser.

How to Use

  1. 1Pick a Target framework (MSW, json-server, Nock, Express, fetch mock, or raw JSON) and set the Base URL.
  2. 2Add endpoints with the "Add endpoint" button — for each one choose the Method, Path and Record count (1–1000).
  3. 3Choose a Data source: Auto for name-based smart fields, From JSON Schema, or From JSON example, then paste your schema or sample object.
  4. 4Optionally type a Seed for reproducible output (or click the dice to randomize); leave it blank for fresh data every run.
  5. 5Press "Generate mock setup" and copy, download, or pipe the generated code — the file name and MIME type match the chosen framework.

Key Benefits

  • Generates real mock code for MSW, json-server, Nock, Express, fetch, or raw JSON — not just sample data
  • Three data sources: name-based auto fields, JSON Schema, or an inferred JSON example
  • Schema-aware: respects type, enum, format (email/uuid/date-time…), min/max and array bounds
  • Optional seed produces identical, reproducible output across runs and machines
  • Per-endpoint method, path and record count, with multiple endpoints in one setup
  • Live preview plus a stats bar showing endpoint count, total records and byte size
  • Runs fully in the browser — your schema and data never leave the page

Common Use Cases

  • Standing up MSW handlers so a frontend can develop against an API that does not exist yet
  • Seeding a json-server db.json for a quick prototyping backend
  • Generating Nock interceptors or a fetch mock for deterministic unit tests via a fixed seed
  • Producing a throwaway Express mock server for a demo or integration spike
  • Turning one real example response into hundreds of varied records for load or UI testing

Mock settings

Fresh data each run

Endpoints

Endpoint 1

Fix the input to preview.

Run to generate your mock setup.

Was this tool helpful?

Share Your Experience

Help others discover this tool!

Related tools