WireMock Cloud (via WireMock) supports a set of match operations that can be used against the request’s query, headers, cookies and body.

This article provides an overview of these matchers. The names shown are the exact keys used in the WireMock/WireMock Cloud JSON API.

equalTo

Only matches if the input string is exactly equal to the expected value.

binaryEqualTo

Like equalTo but compares bytes rather than strings. Useful when you need to match e.g. an uploaded image.

matches

Matches the input string against a Java style regular expression.

doesNotMatch

The negative of matches. Will match if the incoming value does not match the regular expression.

contains

Matches if the input string contains the expected value.

equalToJson

Matches if the input string is valid JSON and is semantically equal to the expected value. This is often a better choice than equalTo when dealing with JSON as it will ignore differences in whitespace, and it is optionally possible to ignore array orderings and extra object attributes. It also provides the concept of placeholders, allowing you to selectively ignore or merely constrain specific JSON elements.

The underlying implementation for equalToJson is supplied by JSONUnit.

You can learn more about working with JSON in the Matching JSON article.

matchesJsonPath

Tests the input JSON string against a JSONPath expression, and returns a match if one or more elements are returned. No match will be returned if the input is not valid JSON.

The actual JSONPath evaluation is performed by the Java JSONPath implementation.

equalToXml

Matches if the input string is valid XML and is semantically equal to the expected value. Like with matchesJsonPath this ignores differences in whitespace and supports placeholders so that specific element values can be ignored.

The underlying implementation for equalToXml is supplied by XMLUnit.

You can learn more about working with XML in the Matching XML article.

matchesXPath

Tests the input XML string against an XPath 1.0 expression, and returns a match if one or more elements are returned. No match will be returned if the input is not valid XML.

before, after and equals(date/time)

Tests the input matches a date/time. Date/times can be Absolute or Relative and the expected format can also be configured using Java’s date time format.

before

The date/time must be before the expected date config.

after

The date/time must be after the expected date config.

equals (date/time)

The date/time must exactly match the expected date config.

You can read more about the possible configure options available for wiremock here