Skip to main content
A request matcher is the part of an expectation that decides whether an incoming request should trigger the expectation’s action. MockServer supports two matcher types:
  • Request properties matcher — matches by HTTP properties such as method, path, headers, query parameters, cookies, and body
  • OpenAPI matcher — matches against an OpenAPI v3 specification (see OpenAPI)
All string fields in a request properties matcher accept plain strings, Java-style regular expressions, or JSON Schema. Prefix a value with ! (in JSON/REST) or wrap it with not() (in Java) to negate it. Prefix a key with ? to make it optional.

Method

Use a regex to match multiple methods. To match any method except GET:

Path

Match an exact path, a regex, or negate it.

Path parameters

Use {paramName} placeholders in the path and specify values under pathParameters.
Use a JSON Schema value for more complex constraints:

Query parameters

Mark a parameter as optional by prefixing the key with ?:
By default, query parameter matching uses SUB_SET mode — the request must contain at least one matching value per non-optional key, but may contain additional parameters. Set "keyMatchStyle": "MATCHING_KEY" to require all values for a key to match.

Headers

Match headers with regex names or values:
Negate a header value:
Require a header to be absent:
Use a JSON Schema to validate a header value:
Make a header optional:

Cookies

Cookies follow the same pattern as headers but map each name to a single value.
Use a JSON Schema for the cookie value:
Mark a cookie as optional with the ? prefix:

Body

MockServer supports many body match types.
Match exact body content:
Match a substring using subString: true:
In Java: .withBody(regex("starts_with_.*"))
Strict matching (all fields, array order, no extra fields):
Partial matching — only the fields you specify must be present:
Use JSONUnit placeholders to ignore fields or match by type:
Matches if at least one value is returned by the expression:
Matches if at least one node is returned by the expression:
In Java: .withBody(xpath("/bookstore/book[price>30]/price"))Negate the XPath match:
Exact XML match:
Use XMLUnit placeholders to ignore elements or match by type:

Negation

Prefix any string value with ! in JSON/REST to negate it. In Java, wrap it with not():

OpenAPI matcher

You can also use an OpenAPI v3 specification as the request matcher. See OpenAPI for details.