Skip to content

Mock File Schema

This page is a complete reference for the JSON structure of a Mimic mock file. For a friendlier introduction, start with the Mock Files guide.

{
"method": "string",
"path": "string",
"status": 200,
"response": "any",
"consume_body": false,
"query_params": { /* ... */ },
"headers": { /* ... */ },
"body": { /* ... */ },
"response_headers": { /* ... */ },
"delay_ms": 0,
"sequence": [ /* ... */ ]
}
FieldTypeRequiredDescription
methodstringyesHTTP method. Case-insensitive but conventionally uppercase: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS.
pathstringyesURL path. Must start with /. May contain named parameters (:id, {id}) — see Path Parameters. No other wildcards are supported.
statusnumberyesHTTP status code returned for matching requests.
responseanyyesThe JSON value returned as the response body. Can be an object, array, string, number, boolean, or null. String values support {{ }} templating.
consume_bodybooleannoIf true, Mimic reads and discards the request body before responding. Required for file uploads and large payloads. Default: false.
query_paramsobjectnoMatch against query string parameters.
headersobjectnoMatch against request headers.
bodyobjectnoMatch against the request body.
response_headersobjectnoCustom response headers (name → string value). See Custom Response Headers.
delay_msnumber or objectnoDelay before responding: a fixed number of milliseconds, or { "min": number, "max": number } for a random range. See Response Delays.
sequencearraynoA list of { status, response, delay_ms?, repeat? } steps served one per request. See Stateful Sequences.
{
"query_params": {
"params": {
"<param_name>": "<matcher>"
},
"strict": false
}
}
FieldTypeRequiredDescription
paramsobjectyesMap of parameter name to matcher value.
strictbooleannoIf true, the request must contain only the listed params. Default: false.

A matcher in params can be:

FormMatches when
"value" (string)Param is present and equal to "value".
{ "regex": "^pattern$" }Param is present and matches the regex.
{ "any": null }Param is present, value is anything.

See Query Parameter Matching for examples.

{
"headers": {
"required": {
"<header_name>": "<matcher>"
},
"forbidden": ["<header_name>"],
"strict": false
}
}
FieldTypeRequiredDescription
requiredobjectnoHeaders that must be present and match.
forbiddenstring[]noHeader names that must not be present.
strictbooleannoIf true, the request must contain only the listed required headers. Default: false.
FormMatches when
"value" (string)Header value equals "value" exactly.
{ "prefix": "Bearer " }Header value starts with the prefix.
{ "contains": "json" }Header value contains the substring.
{ "regex": "^pattern$" }Header value matches the regex.
{ "any": null }Header is present, value is anything.

Header names are compared case-insensitively. See Header Matching for examples.

{
"body": {
"type": "json" | "text" | "form",
/* type-specific fields */
}
}
FieldTypeRequiredDescription
exactanynoEntire JSON body must equal this value.
partialobjectnoThese fields must be present in the body. Extras are allowed unless strict: true.
strictbooleannoWith partial, reject requests that have extra fields.

Use exactly one of exact or partial.

FieldTypeRequiredDescription
exactstringnoBody must equal this string exactly.
containsstringnoBody must contain this substring.
regexstringnoBody must match this regex.

Use exactly one of exact, contains, or regex.

FieldTypeRequiredDescription
fieldsobjectyesForm fields that must be present with the given values.
strictbooleannoIf true, reject requests with extra fields. Default: false.

See Request Body Matching for examples.

{
"response_headers": {
"<header_name>": "<string value>"
}
}

A flat map of header name to string value, applied to the response. Names are case-insensitive. Content-Type: application/json is added automatically unless these headers already set one. See Custom Response Headers.

{ "delay_ms": 2000 }

or a random range:

{ "delay_ms": { "min": 100, "max": 3000 } }
FormDescription
numberFixed delay in milliseconds before the response is sent.
{ "min": number, "max": number }A fresh random delay, uniformly sampled between min and max (inclusive), on every request.

See Response Delays.

{
"sequence": [
{ "status": 200, "response": { /* ... */ }, "delay_ms": 0, "repeat": false }
]
}

An array of steps served one per request, in order.

FieldTypeRequiredDescription
statusnumberyesHTTP status code for this step.
responseanyyesResponse body for this step.
delay_msnumbernoDelay in milliseconds for this step only; overrides the mock-level delay_ms.
repeatbooleannoIf true, this step is served for all subsequent calls. Default: false.

If no step sets repeat: true, the last step repeats once the array is exhausted. An empty array falls back to the mock’s top-level status/response. See Stateful Sequences.

A mock that combines path parameters, templating, custom headers, a delay, and a sequence:

{
"method": "POST",
"path": "/orders/:id/pay",
"status": 200,
"response": { "order_id": "{{path.id}}", "status": "paid" },
"response_headers": {
"X-Processed-By": "mimic"
},
"delay_ms": { "min": 50, "max": 300 },
"sequence": [
{ "status": 503, "response": { "error": "payment gateway unavailable" } },
{
"status": 200,
"response": { "order_id": "{{path.id}}", "status": "paid" },
"repeat": true
}
]
}
  • path captures :id, which both sequence steps echo back via {{path.id}}.
  • The first call to /orders/<any id>/pay returns 503; every call after that returns 200 — and this holds across different order ids, since it’s one sequence per mock, not per id.
  • Every response (both steps) carries the X-Processed-By: mimic header and a random 50–300ms delay.

A mock that combines every matcher type:

{
"method": "POST",
"path": "/api/search",
"status": 200,
"consume_body": true,
"query_params": {
"params": {
"type": "user",
"page": { "regex": "^[0-9]+$" }
},
"strict": false
},
"headers": {
"required": {
"authorization": { "prefix": "Bearer " },
"content-type": { "contains": "json" }
},
"forbidden": ["x-debug"],
"strict": false
},
"body": {
"type": "json",
"partial": {
"query": "Alice"
}
},
"response": {
"results": [
{ "id": 1, "name": "Alice Johnson" }
],
"total": 1
}
}

This mock only matches a request that:

  • Uses POST to /api/search
  • Has ?type=user&page=<digits> in the query string
  • Has an Authorization header starting with Bearer
  • Has a Content-Type header containing json
  • Does not have an x-debug header
  • Has a JSON body containing at least {"query": "Alice"}

See Match Priority for how this scores against other mocks for the same path.