Route Behavior

Conditional Matching

A route doesn't have to return the same thing every time. Add match conditions to a route and MockBase only returns that route's response when the incoming request satisfies all of them — otherwise it moves on to the next candidate route for that method and path.

Adding a condition

Each condition has three parts:

  • Source — where to look: query, header, cookie, body, graphql_operation (matches a GraphQL request's operation name — see GraphQL), soap_body (reads an element out of an XML/SOAP envelope — see SOAP & XML), or scenario (matches the mock's active scenario — see Scenarios).
  • Key — the parameter/header/cookie name, a dot-path into the JSON body (e.g. user.email reaches a nested field), or a dot-path of element names for soap_body (e.g. GetUser.userId). Header lookups are case-insensitive. Not used for graphql_operation or scenario.
  • Operator — equals, not_equals, contains, exists, or regex.

A route can have multiple conditions; all of them must pass for that route to match. A condition whose regex pattern is itself invalid simply never matches — it won't error out your request.

Which route wins

When more than one route could match the same method and path:

  1. Routes are tried in order of priority (higher number first).
  2. Routes with equal priority are tried in the order you added them.
  3. The first route whose conditions all pass — or that has no conditions at all — is the one that responds.

A route with no conditions always passes, so give it the lowest priority among its siblings if you want it to act as a catch-all fallback after more specific, conditioned routes.

This same priority order applies to routes with {name} path segments, too: MockBase prefers an exact static path over a parameterized one, and among parameterized routes prefers the more specific one (fewer {name} segments) before falling back to priority.

No match

If no route for a method and path matches, MockBase returns 404 with {"error": "route_not_found"} — unless Record & Replay is configured for the mock, in which case the request is proxied to your upstream instead.

If you're getting an unexpected 404 from a route you're sure exists, a condition is usually the reason: check the route's conditions against what the Request Inspector shows was actually sent.

Example

GET /users with two routes:

PriorityConditionResponse
10header X-Env equals staginga staging-flavored payload
0(none)the normal payload

A request with X-Env: staging gets the first route; every other request falls through to the unconditioned one.