http_server_mock/matcher

Builder for RequestMatcher — the rules that decide whether an incoming request should be handled by a given stub.

Start with new() and pipe through the constraint functions you need. Constraints that are not set match anything, so a new() with no constraints will match every request.

let m =
  matcher.new()
  |> matcher.method(http.Post)
  |> matcher.path("/orders")
  |> matcher.header("x-api-key", "secret")
  |> matcher.body_json("{\"amount\":100}")

Values

pub fn apply_string_matcher(
  string_matcher: types.StringMatcher,
  value: String,
) -> Bool

Applies a StringMatcher to value, returning True if it matches.

Exposed for use in custom filtering logic over recorded_requests.

pub fn body_containing(
  request_matcher: types.RequestMatcher,
  fragment: String,
) -> types.RequestMatcher

Constrains the matcher to only match requests whose body contains fragment as a substring.

pub fn body_equal_to(
  request_matcher: types.RequestMatcher,
  body: String,
) -> types.RequestMatcher

Constrains the matcher to only match requests whose body is exactly equal to body.

pub fn body_json(
  request_matcher: types.RequestMatcher,
  json: String,
) -> types.RequestMatcher

Constrains the matcher to only match requests whose body is semantically equal to json when both are parsed as JSON (whitespace and key order are ignored).

pub fn body_matcher(
  request_matcher: types.RequestMatcher,
  body_matcher: types.BodyMatcher,
) -> types.RequestMatcher

Constrains the matcher using a custom BodyMatcher.

Use this when none of the convenience functions (body_equal_to, body_containing, body_json) cover your use case.

pub fn header(
  request_matcher: types.RequestMatcher,
  key: String,
  value: String,
) -> types.RequestMatcher

Constrains the matcher to only match requests that have the header key set to exactly value. Header names are compared case-insensitively.

Can be called multiple times to require several headers.

pub fn header_matching(
  request_matcher: types.RequestMatcher,
  key: String,
  string_matcher: types.StringMatcher,
) -> types.RequestMatcher

Constrains the matcher to only match requests that have the header key satisfying the given StringMatcher. Header names are compared case-insensitively.

Can be called multiple times to require several headers.

pub fn matches(
  request_matcher: types.RequestMatcher,
  recorded_request: types.RecordedRequest,
) -> Bool

Returns True if recorded_request satisfies all constraints on request_matcher.

This is the same matching logic the server uses internally. You can call it directly when filtering recorded_requests for custom assertions.

pub fn method(
  request_matcher: types.RequestMatcher,
  method: http.Method,
) -> types.RequestMatcher

Constrains the matcher to only match requests with the given HTTP method.

pub fn new() -> types.RequestMatcher

Returns a new RequestMatcher with no constraints — matches every request.

pub fn path(
  request_matcher: types.RequestMatcher,
  path: String,
) -> types.RequestMatcher

Constrains the matcher to only match requests whose path is exactly equal to path.

Use path_matching or path_contains for partial matches.

pub fn path_contains(
  request_matcher: types.RequestMatcher,
  fragment: String,
) -> types.RequestMatcher

Constrains the matcher to only match requests whose path contains fragment as a substring.

pub fn path_matching(
  request_matcher: types.RequestMatcher,
  string_matcher: types.StringMatcher,
) -> types.RequestMatcher

Constrains the matcher to only match requests whose path satisfies the given StringMatcher.

Use this when you need Contains, Prefix, or Suffix path matching instead of an exact match.

pub fn query_param(
  request_matcher: types.RequestMatcher,
  key: String,
  value: String,
) -> types.RequestMatcher

Constrains the matcher to only match requests that have the query parameter key set to exactly value.

Can be called multiple times to require several query parameters.

pub fn query_param_matching(
  request_matcher: types.RequestMatcher,
  key: String,
  string_matcher: types.StringMatcher,
) -> types.RequestMatcher

Constrains the matcher to only match requests that have the query parameter key satisfying the given StringMatcher.

Can be called multiple times to require several query parameters.

Search Document