Routing & Matching Reference
Mockzilla's routing engine gives you full control over how your incoming requests match your mocks. This means you can create multiple responses for the same path based on URL segments or query parameters.
Path Matching Strategies
| Strategy | Description | Best Use Case |
|---|---|---|
| Exact | Path must match character-for-character. | Static routes: /login, /profile. |
| Wildcard | Use * to capture dynamic URL segments. | Routes with IDs: /users/*, /posts/*/comments. |
| Substring | Matches if the mock path is contained anywhere in the URL. | General prefixes: /api/v1 to catch everything under it. |
Wildcard Variants
With Wildcard Match Type, you can return different data for different captured segments.
Single Wildcard
On /users/*:
- Key:
1-> Returns Gold Member profile. - Key:
2-> Returns Basic Member profile. - Key:
*-> Returns a default 404 or Generic User.
Multiple Wildcards
If you use multiple *, the Variant Key is formed by joining captured segments with a pipe (|).
Example Pattern: /api/users/*/orders/*
| Request Path | Captured Segments | Variant Key to Use |
|---|---|---|
/api/users/123/orders/456 | 123, 456 | `123 |
/api/users/alice/orders/latest | alice, latest | `alice |
Matching by Query Parameters
You can enforce strict matching based on the Query String.
- In Advanced Options, add a Key (e.g.,
role) and a Value (e.g.,admin). - Mockzilla will only serve this mock if the incoming URL includes
?role=admin. - You can stack multiple parameters for complex test cases (e.g.,
?role=admin&beta=true).
You can also type query parameters directly in the Endpoint Path field, such as /users?role=admin. Mockzilla keeps that full URL-style path visible in the editor, syncs it with Advanced Options, and updates the preview URL as you edit either place.
Strategy Precedence
If multiple mocks could match a single request, Mockzilla follows this precedence:
- Exact (Highest priority)
- Wildcard
- Substring
Proxy & Record
When a matched mock has meta.proxyTargetUrl:
- It proxies the request to that URL.
- It auto-captures the response.
- It creates a new exact mock in the same folder.
If no mock matches, Mockzilla returns 404; proxy recording is never enabled by folder metadata.
See the Proxy & Record Guide for more.
FAQ: Handling URL Overlap
- Scenario: I have
/users/admin(Exact) and/users/*(Wildcard). - Answer: Mockzilla will always pick the Exact match first. Only if the path is not "admin" (e.g.,
/users/123) will it move to the Wildcard match.
