MirageAPI documentation

Everything you need to turn an OpenAPI spec into a working mock server, in the browser or on your own machine.

Using the web app

  1. Open the app.
  2. Upload a spec file, paste its contents, load it from a public URL (GitHub file links work), or click Load demo to try the sample customer/order API.
  3. Review the validation report for errors, warnings and suggestions about your spec.
  4. Click Start Server. Every path in your spec is now live on the same domain, for example https://mirageapi.com/customers.
  5. Pick an endpoint in the explorer and send a request. The controls above the response let you force a status code, add latency, use the spec's examples or turn validation off.

Tip: link straight to a spec with https://mirageapi.com/app/?spec=<url> and it loads when the page opens.

Mocks in the web app are tied to your browser session (a cookie), so each visitor gets their own isolated mock server. Sessions last up to 24 hours. To call them from another tool, machine or teammate, share a mock URL or run the CLI.

Sharing a mock URL

Click Share in the spec bar to get a public link such as https://mirageapi.com/m/Ab3dE7xY. Anyone — a teammate, a frontend app, a CI job — can call your endpoints under it without a browser session:

curl https://mirageapi.com/m/Ab3dE7xY/customers

Running the CLI locally

The CLI serves your spec on localhost with no session or browser needed — ideal for frontend development and CI.

git clone https://github.com/venkatbandaru99/mirage.git
cd mirage
yarn install        # or: npm install

node src/index.js --spec ./examples/sample-spec.yaml --port 3000

On startup the CLI validates the spec, prints every registered endpoint and starts listening:

✓ Spec loaded and validated successfully
Mirage mock server running on http://localhost:3000
📋 Endpoints:
   GET /customers
   POST /customers
   GET /customers/{id}
   GET /orders
   POST /orders
   GET /orders/{id}

Options

OptionDescription
-s, --spec <file>Path to the OpenAPI spec (JSON or YAML). Required.
-p, --port <number>Port to listen on. Default 3000.
--no-validateAccept requests that don't match the spec (validation is on by default).
--quietSuppress the startup banner.
-w, --webRun the full web app instead (requires yarn build and a SESSION_SECRET environment variable).

Every request is logged to the console with its timestamp, method and path. CORS is enabled for all origins, so a frontend on another port can call the mock directly.

Supported spec formats

Specs are validated with swagger-parser before any route is registered, so a broken spec fails fast with a clear message.

How data is generated

Responses are generated from the success response schema (200, then 201, then default) using Faker. Each request produces new data.

SchemaGenerated value
enumA random value from the list (any type)
string, format: emailA valid email address
string, format: uuidA v4 UUID
string, format: date / date-time / timeA past date (YYYY-MM-DD), ISO 8601 timestamp, or HH:MM:SS
string, format: uri / urlA URL
string, format: phone / password / byte / binaryA phone number, password, base64 string or hex string
string with minLength/maxLengthText whose length is within the bounds (default 5–50 characters)
string with a common field nameA realistic value based on the property name: firstName, lastName, name, username, email, phone, street, city, state, country, postalCode, company, productName, url, currency and more, including suffixes such as billingCity. Names ending in Id get a UUID. Used only when the value also satisfies the field's length and pattern constraints.
string with patternA value generated from the regular expression and checked against it. Complex patterns (lookaheads, backreferences) fall back to a numeric or word value.
integer / numberA value within minimum/maximum (default 0–1000), honouring exclusiveMinimum, exclusiveMaximum and multipleOf. Numbers are rounded to 2 decimals.
booleantrue or false
arrayBetween minItems and maxItems items (default 1–5), each generated from items
objectAll required properties, plus each optional property about 70% of the time. additionalProperties schemas add a few extra keys.
allOf / oneOf / anyOfallOf schemas are merged; for oneOf/anyOf one option is picked at random

How requests are handled

RequestResponse
GET, DELETE and other methods200 with data generated from the success response schema
POST, PUT, PATCH with a JSON body201 echoing your body, with a generated id and a createdAt timestamp (if not already present)
POST, PUT, PATCH without a body201 with data generated from the 201/200/default schema
Path parameters such as /customers/{id}Any value matches the route; the value is then validated against the parameter's schema
A request that doesn't match the spec400 listing each problem (see request validation)
A path not in the spec404 with the list of available routes

Request validation

Requests are checked against the spec before a response is generated: path parameters, query parameters (required, type, enum, format, ranges) and the JSON body. A request that doesn't match gets a 400 listing every problem:

{
  "error": "Request validation failed",
  "errors": [
    { "in": "body", "path": "/lastName", "message": "must have required property 'lastName'" },
    { "in": "body", "path": "/email", "message": "must match format \"email\"" }
  ]
}

readOnly properties such as a server-generated id are not required in request bodies. To skip validation, send ?__validate=false or the X-Mirage-Validate: false header, untick Validate requests in the app, or start the CLI with --no-validate.

Simulating status codes, latency and examples

Add these to any mock request (in the app, use the controls above the response). Query parameters starting with __ are MirageAPI's own and are never validated against your spec.

ControlQuery parameterHeader
Force a status code?__status=404X-Mirage-Status: 404 or Prefer: code=404
Add latency?__delay=800 or a random range ?__delay=200-800 (max 10 s)X-Mirage-Delay: 800
Return the spec's examples?__example=truePrefer: example or X-Mirage-Example: true
Skip validation?__validate=falseX-Mirage-Validate: false

A forced status code uses the response your spec defines for that code (its schema or example) when there is one, and a generic { error, status, message } body otherwise; 204 has no body. In example mode the response-level example is returned when present; otherwise property example values are used and anything without one is generated.

Built-in routes

Current limitations

Have a feature request? Open an issue on GitHub.