Base Usage
Request Matching
(This documentation is adapted from the original documentation of WireMock.)
Mimus Serve supports matching of requests to stubs and verification queries using the following attributes:
- URL
- HTTP Method
- Query parameters
- Headers
- Cookies
- Request body
Soon, we will also support:
- Basic authentication (a special case of header matching)
- Multipart/form-data
URL matching
URLs can be matched either by equality or by regular expression. You also have a choice of whether to match just the path part of the URL or the path and query together.
It is usually preferable to match on path only if you want to match multiple query parameters in an order invariant manner.
Equality matching on path and query
Regex matching on path and query
Equality matching on the path only
Regex matching on the path only
Matching other attributes
All request attributes other than the URL can be matched using the following set of operators.
This works for the following matching attributes:
- Query parameters
- Headers
- Cookies
- Request Body
Equality
Deems a match if the entire attribute value equals the expected value.
Case-insensitive equality
Deems a match if the entire attribute value equals the expected value, ignoring case.
Binary Equality
Deems a match if the entire binary attribute value equals the expected value. Unlike the above equalTo operator, this compares byte arrays (or their equivalent base64 representation).
Substring (contains)
Deems a match if the a portion of the attribute value equals the expected value.
Regular expression
Deems a match if the entire attribute value matched the expected regular expression.
It is also possible to perform a negative match i.e. the match succeeds when the attribute value does not match the regex:
JSON equality
Deems a match if the attribute (most likely the request body in practice) is valid JSON and is a semantic match for the expected value.
JSON with string literal:
Less strict matching
By default different array orderings and additional object attributes will trigger a non-match. However, both of these conditions can be disabled individually.
JSON Path
Deems a match if the attribute value is valid JSON and matches the JSON Path expression supplied. A JSON body will be considered to match a path expression if the expression returns either a non-null single value (string, integer etc.), or a non-empty object or array.
Presence matching
Deems a match if the attribute value is present in the JSON.
Request body example:
Equality matching
Deems a match if the attribute value equals the expected value.
JSON:
Request body example:
Regex matching
Deems a match if the attribute value matches the regex expected value.
Request body example:
Size matching
Deems a match if the attribute size matches the expected size.
Request body example:
Nested value matching
The JSONPath matcher can be combined with another matcher, such that the value returned from the JSONPath query is evaluated against it:
Since Mimus Serve's matching operators all work on strings, the value selected by the JSONPath expression will be coerced to a string before the match is evaluated. This true even if the returned value is an object or array. A benefit of this is that this allows a sub-document to be selected using JSONPath, then matched using the equalToJson operator. E.g. for the following request body:
The following will match:
Absence
Deems a match if the attribute specified is absent from the request.
Presence
Deems a match if the attribute specified is present in the request.