This section describes matcher functions designed to target and match the request path, such as http://localhost:8080/my-path.
path
Specifies the expected URL path that incoming requests must match for the mock server to respond.
This is useful for targeting specific endpoints, such as API routes, to ensure only relevant requests trigger the mock response.
Parameters
path: A string or other value convertible to String that represents the expected URL path.
Example
Returns
The updated When instance, allowing method chaining for additional configuration.
path_not
Specifies the URL path that incoming requests must not match for the mock server to respond.
This is helpful when you need to exclude specific endpoints while allowing others through.
To add multiple excluded paths, invoke this function multiple times.
Parameters
path: A string or other value convertible to String that represents the URL path to exclude.
Example
Returns
The updated When instance, allowing method chaining for further configuration.
path_includes
Specifies a substring that the URL path must contain for the mock server to respond.
This constraint is useful for matching URLs based on partial segments, especially when exact path matching isn’t required.
Parameters
substring: A string or any value convertible to String representing the substring that must be present in the URL path.
Example
Returns
The updated When instance to allow method chaining for further configuration.
path_excludes
Specifies a substring that the URL path must not contain for the mock server to respond.
This constraint is useful for excluding requests to paths containing particular segments or patterns.
Parameters
substring: A string or other value convertible to String representing the substring that should not appear in the URL path.
Example
Returns
The updated When instance to enable method chaining for additional configuration.
path_prefix
Specifies a prefix that the URL path must start with for the mock server to respond.
This is useful when only the initial segments of a path need to be validated, such as checking specific API routes.
Parameters
prefix: A string or other value convertible to String representing the prefix that the URL path should start with.
Example
Returns
The updated When instance to allow method chaining for further configuration.
path_prefix_not
Specifies a prefix that the URL path must not start with for the mock server to respond.
This constraint is useful for excluding paths that begin with particular segments or patterns.
Parameters
prefix: A string or other value convertible to String representing the prefix that the URL path should not start with.
Example
Returns
The updated When instance to allow method chaining for additional configuration.
path_suffix
Specifies a suffix that the URL path must end with for the mock server to respond.
This is useful when the final segments of a path need to be validated, such as file extensions or specific patterns.
Parameters
suffix: A string or other value convertible to String representing the suffix that the URL path should end with.
Example
Returns
The updated When instance to allow method chaining for further configuration.
path_suffix_not
Specifies a suffix that the URL path must not end with for the mock server to respond.
This constraint is useful for excluding paths with specific file extensions or patterns.
Parameters
suffix: A string or other value convertible to String representing the suffix that the URL path should not end with.
Example
Returns
The updated When instance to allow method chaining for further configuration.
path_matches
Specifies a regular expression that the URL path must match for the mock server to respond.
This method allows flexible matching using regex patterns, making it useful for various matching scenarios.
Parameters
regex: An expression that implements Into<Regex>, representing the regex pattern to match against the URL path.
Example
Returns
The updated When instance to allow method chaining for additional configuration.
Errors
This function will panic if the provided regex pattern is invalid.