Routing & Matching Reference
Every request to /api/mock/{folder}/{path} goes through the same steps:
- Folder: find the folder from the URL.
- Candidates: keep the folder's enabled mocks with the same HTTP method.
- Filter: drop mocks whose path or required query parameters don't match.
- Score: pick the highest-scoring mock (see Strategy precedence).
- Variant: for a wildcard mock, pick a variant (see Wildcard variants).
- Respond: apply the delay, then proxy, or return the static, echoed, or dynamic response.
The path is relative to the folder. Trailing slashes and repeated slashes are
normalized, so /users/1/ and /users//1 are both treated as /users/1. For mocks
in a subfolder, the subfolder path is added in front of the mock endpoint; see
Mock Subfolders.
Path matching strategies
| Strategy | Matches when | Example endpoint | Matches | Doesn't match |
|---|---|---|---|---|
| Exact | The path equals the endpoint | /users/me | /users/me | /users/me/settings |
| Wildcard | The path fits the * pattern | /users/* | /users/7, /users/7/posts | /users |
| Substring | The endpoint appears anywhere in the path | /v1 | /v1/users, /api/v1 | /v2/users |
Match Type is Exact by default, even when the endpoint contains *. Select
Wildcard to turn on capturing and variants.
Wildcard matching
Each * captures one or more characters, including /. Captures are exposed to
responses as $.params.[0], $.params.[1], … in endpoint order.
| Endpoint | Request path | Captures |
|---|---|---|
/api/products/* | /api/products/p-42 | [0] = p-42 |
/users/*/orders/* | /users/user-7/orders/order-3 | [0] = user-7, [1] = order-3 |
/users/*/orders/* | /users/a/b/orders/c | [0] = a/b, [1] = c |
/files/*/* | /files/a/b/c | [0] = a, [1] = b/c |
/files/* | /files/2024/report.pdf | [0] = 2024/report.pdf |
/api/products/* | /api/products | No match |
Rules:
- Non-empty: a
*never matches an empty string. - Shortest first: each star takes as few characters as it can while the rest still matches. Only the last star absorbs the remaining text.
- End-anchored: a wildcard endpoint must match the end of the path, but can
start partway through it.
/products/*matches/products/1and also/shop/products/1. Write the full prefix (/api/products/*) to avoid this. - Full URLs: an endpoint containing
://must match the whole value from start to end. - Literal characters: every character other than
*matches itself, including.,?, and+.
To build responses from captures, see the Dynamic Wildcard Mocks guide.
Wildcard variants
Once a wildcard mock wins the request, Mockzilla picks the response from its Wildcard Variants:
- A specific variant whose capture list equals the request's captures. Every position must match, and values are compared after URL-decoding.
- The fallback (Add fallback), if one exists. A mock has at most one.
- If neither exists, Return 404 when no variant matches decides:
- On:
404with the errorNo matching variant found. - Off: the mock's stored base response.
- On:
If the mock has no variants at all, the base response is used.
The chosen variant replaces the response body, status code, body type, JSON Schema, and dynamic mode. Echo Request Body is always off for variant responses. Delay and proxy settings stay on the mock and still apply.
Variants are chosen after mock selection. They don't affect which mock wins.
| Endpoint | Variant captures | Request | Result |
|---|---|---|---|
/products/* | p-404 | /products/p-404 | Specific variant |
/products/* | p-404 | /products/p-42 | Fallback, or 404/base |
/users/*/orders/* | user-7, order-3 | /users/user-7/orders/order-3 | Specific variant |
/users/*/orders/* | user-7, order-3 | /users/user-7/orders/order-9 | Fallback, or 404/base |
Matching by query parameters
Use Advanced Options → Query Parameters to require query values before a mock can match. Add one row per required key.
| Required row | Request query | Result |
|---|---|---|
| (none) | ?page=2, or no query | Matches |
category = books | ?category=books&page=2 | Matches; extra keys are allowed |
category = books | ?category=games | Doesn't match |
category = * | ?category=games | Matches; any value |
category = * | ?category= | Matches; an empty value counts |
category = * | ?page=2 | Doesn't match; the key is missing |
category = boo* | ?category=books | Matches values starting with boo |
role = adm* | ?role=superadmin | Doesn't match; the pattern starts at the beginning |
Rules:
- Every row must match. Requests can include extra parameters.
- Key names match exactly and are case-sensitive.
- A value without
*must equal the request value.*matches any characters, including none, and the pattern covers the whole value. - A repeated key (
?tag=a&tag=b) uses its last value.
You can also type query parameters in the Endpoint Path field, such as
/users?role=admin. The editor moves them into Advanced Options and keeps both
places in sync. The saved endpoint never contains ?.
Query rows only control matching. To return a value, reference it in the
response with {{$.query.key}}. Values are strings; see
Use request values in responses.
Query values don't change schema generation. For example, ?limit=10 doesn't change
an array's length; set minItems and maxItems for that.
Strategy precedence
Each mock that passes the path and query filters gets a score. The highest score wins.
score = path type + 10 × required query rows + exact query values + endpoint length
| Part | Points |
|---|---|
| Path type | Exact 300, Wildcard 200, Substring 100 |
| Each required query row | +10 |
Each query row with an exact value (no *) | +1 |
| Endpoint path length | +1 per character, query string excluded |
Worked examples
Request /users/admin:
| Mock | Score |
|---|---|
Exact /users/admin | 300 + 12 = 312 ✅ |
Wildcard /users/* | 200 + 8 = 208 |
Substring /users | 100 + 6 = 106 |
Request /users/1?role=admin:
| Mock | Score |
|---|---|
Wildcard /users/*, role = admin | 200 + 10 + 1 + 8 = 219 ✅ |
Wildcard /users/*, role = * | 200 + 10 + 8 = 218 |
Wildcard /users/* | 200 + 8 = 208 |
Request /users/1/profile?role=admin:
| Mock | Score |
|---|---|
Wildcard /users/*, role = admin | 200 + 11 + 8 = 219 ✅ |
Wildcard /users/*/profile | 200 + 16 = 216 |
The last example shows that a query row (+10) usually outweighs a longer path. Path
type is worth the most, but it can be overtaken: an exact mock beats a wildcard with
the same query rows, while a wildcard with about ten extra query rows can outscore an
exact path.
Ties
When scores are equal:
- Mocks without a proxy target win over proxy mocks.
- The most recently created mock wins.
Avoid relying on ties. Give overlapping mocks distinct endpoints or query rows, or disable the one you don't want.
Proxy & Record
When the matched mock has meta.proxyTargetUrl:
- It proxies the request to that URL, keeping the query string. Each
*in the target is replaced by the matching wildcard capture. - It records the response as a new exact mock in the same folder and subfolder.
- The recording answers only the exact path and query it captured; a request with a different or extra query still reaches the proxy.
If no mock matches, Mockzilla returns 404. Folder settings never turn on proxy
recording by themselves.
See the Proxy & Record Guide for more.
FAQ
I have /users/admin (Exact) and /users/* (Wildcard). Which one answers
/users/admin?
The exact mock (312 vs 208). It stays the winner unless the wildcard mock has about
ten more required query rows.
How do I return a different response for one ID without a second mock? Add a specific variant for that capture value on the wildcard mock.
Why does my mock return 404 when the path is right?
Check the HTTP method, that the mock is enabled, and every required query row. A
key = * row still requires the key to be present.
Why does /products/* answer /shop/products/1?
Wildcards are anchored to the end of the path, not the start. Use the full prefix.
