Skip to content

Request matching

The request object of a stub describes which incoming requests it claims. All conditions in a request object must hold — there is no implicit or between keys. See writing stubs for the overall stub shape.

{
"request": {
"method": "POST",
"urlPath": "/api/orders",
"headers": { "X-Api-Key": { "equalTo": "abc" } },
"queryParameters": { "region": { "matches": "eu-.*" } },
"bodyPatterns": [ { "matchesJsonPath": "$.items[0].sku" } ]
},
"response": { "status": 201 }
}

Request-level keys

KeyTypeNotes
urlstringExact match on path plus query string
urlPatternregexPath plus query string
urlPathstringExact match on path only
urlPathPatternregexPath only
urlPathTemplatestringNamed path variables, e.g. /orders/{id}
methodstringDefaults to ANY
schemestringhttp or https
hostvalue matcherA full matcher object, not a bare string
portinteger
headersmap of matchersKey is the header name
queryParametersmap of matchers
formParametersmap of matchersForm-encoded bodies
cookiesmap of matchers
bodyPatternsarray of matchersAll entries must match
multipartPatternsarraySee below
basicAuthCredentials{username, password}
customMatcher{name, parameters}See below

basicAuthCredentials is desugared internally into an Authorization header matcher, so it composes with anything else you match on headers.

urlPathTemplate is what makes named path variables available to templates — {{request.path.id}} only resolves when the stub matched via a template. See template helpers.

Value matchers

These work on header, query parameter, cookie, form parameter and body targets unless noted.

MatcherShapeNotes
equalTostringOptional sibling caseInsensitive: true
containsstring
doesNotContainstring
matchesregexAnchored: the pattern must match the whole value
doesNotMatchregex
absenttrue
andarray of matchers
orarray of matchers
notsingle matcher object
hasExactlyarray of matchersMulti-value fields
includesarray of matchersMulti-value fields
equalToJsonJSONOptions ignoreArrayOrder, ignoreExtraElements
matchesJsonPathstring, or {expression, <sub-matcher>}
matchesJsonSchemaschemaOption schemaVersion
equalToXmlXML stringPlaceholder options below
matchesXPathstring, or {expression, xPathNamespaces, <sub-matcher>}
beforedate/time
afterdate/time
equalToDateTimedate/timeOption actualFormat
binaryEqualTobase64Body only; exact bytes

matchesJsonSchema accepts schemaVersion of V6, V7, V201909 or V202012.

equalToXml accepts enablePlaceholders, placeholderOpeningDelimiterRegex, placeholderClosingDelimiterRegex and exemptedComparisons.

matchesJsonSchema does not support WireMock’s V4 (Draft 4) — the underlying schema library has no Draft 4 implementation.

Multipart bodies

multipartPatterns is an array of part patterns. Each entry carries its own bodyPatterns, and the array as a whole is governed by matchingType, which is ANY or ALL and defaults to ANY.

"multipartPatterns": [
{
"matchingType": "ALL",
"bodyPatterns": [ { "contains": "invoice" } ]
}
]

Stub-level keys

These sit next to request and response, not inside them.

KeyNotes
id / uuidStub identifier
metadataArbitrary JSON, carried through untouched
priorityDefaults to 5; the lowest number wins
scenarioNameSee scenarios
requiredScenarioState
newScenarioState

Custom matchers

The one built-in custom matcher is the GraphQL body matcher:

"customMatcher": {
"name": "graphql-body-matcher",
"parameters": {
"query": "query GetUser($id: ID!) { user(id: $id) { name } }",
"variables": { "id": "42" },
"operationName": "GetUser"
}
}

See GraphQL for the details of how the query, variables and operation name are compared.

Any other name resolves through the user matcher registry described in extending Mockifyr.

Matchers that are not supported

MatcherWhy
clientIpWireMock Cloud only; the open-source WireMock oracle rejects it with 422
equalToNumber, greaterThanNumber and siblingsStandalone number matchers are WireMock Cloud only; the oracle rejects them with 422

Because the open-source oracle refuses these itself, there is no reference behaviour to differentially test against. See limitations for the full list of deferred edges.