Skip to main content

Matchers

A matcher is one condition on the incoming request. All matchers of an expectation must succeed; if one of them fails, the expectation is skipped and the next one is tried.

Creating a matcher​

In the Expectation detail view, click the pencil on the Matchers card, then Add matcher.

Edit matchers

Each row is one matcher and has three parts:

  1. Type - which part of the request is inspected.
  2. Comparator - how the value is compared.
  3. Value - what it is compared with. Matchers with a name (header, query, param) also have a name field.

Changes are applied when you click Save.

Matcher types​

TypeInspectsExample value
methodThe HTTP method of the request.POST
pathThe path of the request, always starting with /./api/login
headerA request header, selected by its name.name Authorization, value Bearer
queryA query parameter, selected by its name.name page, value 2
paramA field of the request body, selected by its name. Works for JSON bodies and form bodies.name username, value tom
Methods are compared case-insensitively

The method value is upper-cased before it is compared, so post, Post and POST all match a POST request.

Comparators​

ComparatorSucceeds when
ISThe request value equals the matcher value.
IS_NOTThe request value differs from the matcher value.
CONTAINSThe request value contains the matcher value.
NOT_CONTAINSThe request value does not contain the matcher value.
START_WITHThe request value starts with the matcher value.
END_WITHThe request value ends with the matcher value.
MATCH_REGEXThe request value matches the matcher value read as a regular expression.
NOT_MATCH_REGEXThe request value does not match the regular expression.
SHOWEDThe name is present on the request (a header, a query parameter or a body field). No value needed.
NOT_SHOWEDThe name is absent from the request. No value needed.
MATCH_GLOBThe request value matches the matcher value read as a glob pattern, for example /users/*.
NO_MATCH_GLOBThe request value does not match the glob pattern.

For SHOWED and NOT_SHOWED the value field is not used - only the name matters. They are handy to tell apart requests that carry an optional parameter from requests that do not, for example query page SHOWED.

Examples​

  • path START_WITH /book/ matches every path that starts with /book/.

  • query teacher_name CONTAINS tom matches requests whose teacher_name query parameter contains "tom".

  • param teacher_name IS tom matches requests whose body contains teacher_name with the value tom:

    {
    "teacher_name": "tom"
    }
  • path MATCH_GLOB /users/* matches /users/1, /users/42 and /users/jane, but not /users/1/posts.

  • header Authorization SHOWED matches requests that send an Authorization header, whatever its value.

  • method IS_NOT DELETE matches everything except DELETE requests.