Match Rules
Route requests to different scenarios based on query parameters, body fields, or headers
Match Rules
Match rules let you conditionally route an incoming request to a specific scenario based on its content — without changing any client code.
A scenario with match rules is served only when all of its rules pass. If none match, the default scenario is used as a fallback.
Rule structure
Each rule has four fields:
| Field | Values | Description |
|---|---|---|
source | query | body | header | path | Where to look in the request |
key | string | The field name (dot notation for nested body fields) |
op | eq | neq | exists | not_exists | The comparison operation |
value | string | Required for eq and neq; ignored for exists/not_exists |
Adding match rules
On the scenario editor, click + Add Rule. A new row appears:
[source ▾] [key] [op ▾] [value] [×]Multiple rules on the same scenario use AND logic — all rules must pass.
Source types
query — URL query parameter
GET /api/mock/products?type=premiumRule: source=query, key=type, op=eq, value=premium
body — Request body field
{ "user": { "role": "admin" } }Rule: source=body, key=user.role, op=eq, value=admin
Nested fields use dot notation. Any depth is supported.
header — HTTP header
X-Tenant: enterpriseRule: source=header, key=x-tenant, op=eq, value=enterprise
Header keys are case-insensitive.
path — Path parameter
For an endpoint with path pattern /users/{id}:
GET /api/mock/users/42Rule: source=path, key=id, op=eq, value=42
Operations
| Operation | Passes when |
|---|---|
eq | Field value exactly equals value |
neq | Field value does not equal value |
exists | Field is present in the request (any value) |
not_exists | Field is absent from the request |
Priority
When multiple scenarios have match rules that could all match the same request, priority determines which one wins. Scenarios with lower priority numbers are evaluated first.
Set priority in the scenario editor. A priority of 0 (default) means all conditional scenarios are evaluated in the order they were created.
Example
A /api/products endpoint with three scenarios:
| Scenario | Match rules | Priority |
|---|---|---|
premium-list | query.type = premium | 0 |
admin-view | body.user.role = admin | 1 |
default | (none — default scenario) | — |
Request GET /api/mock/products?type=premium → served by premium-list
Request with body.user.role = admin → served by admin-view
All other requests → served by default
Edge cases
| Situation | Behaviour |
|---|---|
| Request body is not valid JSON | Rules with source=body are treated as non-matching |
| Placeholder key not found | Replaced with empty string "" |
| Two scenarios with same priority both match | The one created first wins |
| Match rule on the default scenario | Ignored — default always serves as fallback |