Skip to content

Mock Files

A mock file is a single JSON file that describes one HTTP endpoint. Mimic reads every .json file in the mounted mocks directory and turns each one into a route.

Inside the container, mocks live at /app/mocks. With the recommended Docker setup, you mount your local ./mocks folder there:

Terminal window
-v $(pwd)/mocks:/app/mocks:ro

The :ro flag mounts it read-only — Mimic never writes to your mocks folder.

Here is a complete mock with every common field:

{
"method": "GET",
"path": "/users",
"status": 200,
"consume_body": false,
"response": {
"users": [
{ "id": 1, "name": "Alice" }
]
}
}
FieldTypeDescription
methodstringHTTP method: GET, POST, PUT, DELETE, PATCH, etc.
pathstringURL path the request must hit (e.g. /users, /api/v1/orders).
statusnumberHTTP status code to return (200, 201, 404, 500, …).
responseanyThe JSON body to return. Can be an object, array, string, number, or null.
FieldTypeDefaultDescription
consume_bodybooleanfalseWhether Mimic should read the request body. Set to true for file uploads. See File Uploads.
query_paramsobjectMatch against query string parameters. See Query Parameters.
headersobjectMatch against request headers. See Headers.
bodyobjectMatch against the request body. See Request Body.

The filename has no effect on routing — Mimic only cares about the method and path fields inside the file. That said, descriptive names make your mocks folder readable. A common convention:

mocks/
├── get_users.json
├── get_user_by_id.json
├── post_login.json
├── post_logout.json
└── delete_user.json

You can also use subdirectories — Mimic scans recursively:

mocks/
├── auth/
│ ├── login.json
│ └── logout.json
└── users/
├── list.json
└── create.json

On startup, Mimic walks the mocks directory, parses every .json file, and builds a route table in memory. The /health endpoint reports how many mocks were loaded:

Terminal window
curl http://localhost:8080/health
# {"status":"healthy","mocks_loaded":5,"service":"mimic"}

If a file fails to parse — invalid JSON, missing required field — Mimic logs an error and skips that file. The rest still load. Set RUST_LOG=debug to see exactly which file was rejected and why.

If no mock matches an incoming request, Mimic returns a 404 with a structured error:

{
"error": "mock not found",
"method": "GET",
"path": "/some/undefined/path"
}

This is useful for spotting typos and missing mocks during development.