Body
This section describes matcher functions designed to target and match HTTP request body content in incoming HTTP requests.
body
Sets the required HTTP request body content. This method specifies that the HTTP request body must match the provided content exactly.
Note: The body content is case-sensitive and must be an exact match.
Parameters
body
: The required HTTP request body content. This parameter accepts any type that can be converted into aString
.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
body_not
Sets the condition that the HTTP request body content must not match the specified value. This method ensures that the request body does not contain the provided content exactly.
Note: The body content is case-sensitive and must be an exact mismatch.
Parameters
body
: The body content that the HTTP request must not contain. This parameter accepts any type that can be converted into aString
.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
body_includes
Sets the condition that the HTTP request body content must contain the specified substring. This method ensures that the request body includes the provided content as a substring.
Note: The body content is case-sensitive.
Parameters
substring
: The substring that the HTTP request body must contain. This parameter accepts any type that can be converted into aString
.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
body_excludes
Sets the condition that the HTTP request body content must not contain the specified substring. This method ensures that the request body does not include the provided content as a substring.
Note: The body content is case-sensitive.
Parameters
substring
: The substring that the HTTP request body must not contain. This parameter accepts any type that can be converted into aString
.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
body_prefix
Sets the condition that the HTTP request body content must begin with the specified substring. This method ensures that the request body starts with the provided content as a substring.
Note: The body content is case-sensitive.
Parameters
prefix
: The substring that the HTTP request body must begin with. This parameter accepts any type that can be converted into aString
.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
body_prefix_not
Sets the condition that the HTTP request body content must not begin with the specified substring. This method ensures that the request body does not start with the provided content as a substring.
Note: The body content is case-sensitive.
Parameters
prefix
: The substring that the HTTP request body must not begin with. This parameter accepts any type that can be converted into aString
.
Example
Returns
The updated `When’ instance to allow method chaining for additional configuration.
body_suffix
Sets the condition that the HTTP request body content must end with the specified substring. This method ensures that the request body concludes with the provided content as a substring.
Note: The body content is case-sensitive.
Parameters
suffix
: The substring that the HTTP request body must end with. This parameter accepts any type that can be converted into aString
.
Example
Returns
The updated `When’ instance to allow method chaining for additional configuration.
body_suffix_not
Sets the condition that the HTTP request body content must not end with the specified substring. This method ensures that the request body does not conclude with the provided content as a substring.
Note: The body content is case-sensitive.
Parameters
suffix
: The substring that the HTTP request body must not end with. This parameter accepts any type that can be converted into aString
.
Example
Returns
The updated `When’ instance to allow method chaining for additional configuration.
body_matches
Sets the condition that the HTTP request body content must match the specified regular expression. This method ensures that the request body fully conforms to the provided regex pattern.
Note: The regex matching is case-sensitive unless the regex is explicitly defined to be case-insensitive.
Parameters
pattern
: The regular expression pattern that the HTTP request body must match. This parameter accepts any type that can be converted into aRegex
.
Example
Returns
The updated `When’ instance to allow method chaining for additional configuration.
JSON Body
json_body
Sets the condition that the HTTP request body content must match the specified JSON structure. This method ensures that the request body exactly matches the JSON value provided.
Note: The body content is case-sensitive.
Note: This method does not automatically verify the Content-Type
header.
If specific content type verification is required (e.g., application/json
),
you must add this expectation manually.
Parameters
json_value
: The JSON structure that the HTTP request body must match. This parameter accepts any type that can be converted into aserde_json::Value
.
Example
Returns
The updated `When’ instance to allow method chaining for additional configuration.
json_body_includes
Sets the expected partial JSON body to check for specific content within a larger JSON structure.
Attention: The partial JSON string must be a valid JSON string and should represent a substructure of the full JSON object. It can omit irrelevant attributes but must maintain any necessary object hierarchy.
Note: This method does not automatically set the Content-Type
header to application/json
.
You must explicitly set this header in your requests.
Parameters
partial_body
: The partial JSON content to check for. This must be a valid JSON string.
Example
Suppose your application sends the following JSON request body:
To verify the presence of target_attribute
with the value Example
without needing the entire JSON object:
It’s important that the partial JSON contains the full object hierarchy necessary to reach the target attribute.
Irrelevant attributes such as parent_attribute
and child.other_attribute
can be omitted.
json_body_excludes
Sets the expected partial JSON body to ensure that specific content is not present within a larger JSON structure.
Attention: The partial JSON string must be a valid JSON string and should represent a substructure of the full JSON object. It can omit irrelevant attributes but must maintain any necessary object hierarchy.
Note: This method does not automatically set the Content-Type
header to application/json
.
You must explicitly set this header in your requests.
Parameters
partial_body
: The partial JSON content to check for exclusion. This must be a valid JSON string.
Example
Suppose your application sends the following JSON request body:
To verify the absence of target_attribute
with the value Example
:
It’s important that the partial JSON contains the full object hierarchy necessary to reach the target attribute.
Irrelevant attributes such as parent_attribute
and child.other_attribute
in the example can be omitted.
URL Encoded Body
form_urlencoded_tuple
Adds a key-value pair to the requirements for an application/x-www-form-urlencoded
request body.
This method sets an expectation for a specific key-value pair to be included in the request body
of an application/x-www-form-urlencoded
POST request. Each key and value are URL-encoded as specified
by the URL Standard.
Note: The mock server does not automatically verify that the HTTP method is POST as per spec. If you want to verify that the request method is POST, you must explicitly set it in your mock configuration.
Parameters
key
: The key of the key-value pair to set as a requirement.value
: The value of the key-value pair to set as a requirement.
Example
Returns
When
: Returns the modified When
object with the new key-value pair added to the application/x-www-form-urlencoded
expectations.
form_urlencoded_tuple_not
Adds a key-value pair to the negative requirements for an application/x-www-form-urlencoded
request body.
This method sets an expectation for a specific key-value pair to be excluded from the request body
of an application/x-www-form-urlencoded
POST request. Each key and value are URL-encoded as specified
by the URL Standard.
Note: The mock server does not automatically verify that the HTTP method is POST as per spec. If you want to verify that the request method is POST, you must explicitly set it in your mock configuration.
Parameters
key
: The key of the key-value pair to set as a requirement.value
: The value of the key-value pair to set as a requirement.
Example
Returns
When
: Returns the modified When
object with the new key-value pair added to the negative application/x-www-form-urlencoded
expectations.
form_urlencoded_tuple_exists
Sets a requirement for the existence of a key in an application/x-www-form-urlencoded
request body.
This method sets an expectation that a specific key must be present in the request body of an
application/x-www-form-urlencoded
POST request, regardless of its value. The key is URL-encoded
as specified by the URL Standard.
Note: The mock server does not automatically verify that the HTTP method is POST as per spec. If you want to verify that the request method is POST, you must explicitly set it in your mock configuration.
Parameters
key
: The key that must exist in theapplication/x-www-form-urlencoded
request body.
Example
Returns
When
: Returns the modified When
object with the new key existence requirement added to the
application/x-www-form-urlencoded
expectations.
form_urlencoded_tuple_missing
Sets a requirement that a key must be absent in an application/x-www-form-urlencoded
request body.
This method sets an expectation that a specific key must not be present in the request body of an
application/x-www-form-urlencoded
POST request. The key is URL-encoded as specified by the
URL Standard.
Note: The mock server does not automatically verify that the HTTP method is POST as per spec. If you want to verify that the request method is POST, you must explicitly set it in your mock configuration.
Parameters
key
: The key that must be absent in theapplication/x-www-form-urlencoded
request body.
Example
Returns
When
: Returns the modified When
object with the new key absence requirement added to the
application/x-www-form-urlencoded
expectations.
form_urlencoded_tuple_includes
Sets a requirement that a key’s value in an application/x-www-form-urlencoded
request body must contain a specific substring.
This method sets an expectation that the value associated with a specific key must contain a specified substring
in the request body of an application/x-www-form-urlencoded
POST request. The key and the substring are URL-encoded
as specified by the URL Standard.
Note: The mock server does not automatically verify that the HTTP method is POST as per spec. If you want to verify that the request method is POST, you must explicitly set it in your mock configuration.
Parameters
key
: The key in theapplication/x-www-form-urlencoded
request body.substring
: The substring that must be present in the value associated with the key.
Example
Returns
When
: Returns the modified When
object with the new key-value substring requirement added to the
application/x-www-form-urlencoded
expectations.
form_urlencoded_tuple_excludes
Sets a requirement that a key’s value in an application/x-www-form-urlencoded
request body must not contain a specific substring.
This method sets an expectation that the value associated with a specific key must not contain a specified substring
in the request body of an application/x-www-form-urlencoded
POST request. The key and the substring are URL-encoded
as specified by the URL Standard.
Note: The mock server does not automatically verify that the HTTP method is POST as per spec. If you want to verify that the request method is POST, you must explicitly set it in your mock configuration.
Parameters
key
: The key in theapplication/x-www-form-urlencoded
request body.substring
: The substring that must not be present in the value associated with the key.
Example
Returns
When
: Returns the modified When
object with the new key-value substring exclusion requirement added to the
application/x-www-form-urlencoded
expectations.
form_urlencoded_tuple_prefix
Sets a requirement that a key’s value in an application/x-www-form-urlencoded
request body must start with a specific prefix.
This method sets an expectation that the value associated with a specific key must start with a specified prefix
in the request body of an application/x-www-form-urlencoded
POST request. The key and the prefix are URL-encoded
as specified by the URL Standard.
Note: The mock server does not automatically verify that the HTTP method is POST as per spec. If you want to verify that the request method is POST, you must explicitly set it in your mock configuration.
Parameters
key
: The key in theapplication/x-www-form-urlencoded
request body.prefix
: The prefix that must appear at the start of the value associated with the key.
Example
Returns
When
: Returns the modified When
object with the new key-value prefix requirement added to the
application/x-www-form-urlencoded
expectations.
form_urlencoded_tuple_prefix_not
Sets a requirement that a key’s value in an application/x-www-form-urlencoded
request body must not start with a specific prefix.
This method sets an expectation that the value associated with a specific key must not start with a specified prefix
in the request body of an application/x-www-form-urlencoded
POST request. The key and the prefix are URL-encoded
as specified by the URL Standard.
Note: The mock server does not automatically verify that the HTTP method is POST as per spec. If you want to verify that the request method is POST, you must explicitly set it in your mock configuration.
Parameters
key
: The key in theapplication/x-www-form-urlencoded
request body.prefix
: The prefix that must not appear at the start of the value associated with the key.
Example
Returns
When
: Returns the modified When
object with the new key-value prefix exclusion requirement added to the
application/x-www-form-urlencoded
expectations.
form_urlencoded_tuple_suffix
Sets a requirement that a key’s value in an application/x-www-form-urlencoded
request body must end with a specific suffix.
This method sets an expectation that the value associated with a specific key must end with a specified suffix
in the request body of an application/x-www-form-urlencoded
POST request. The key and the suffix are URL-encoded
as specified by the URL Standard.
Note: The mock server does not automatically verify that the HTTP method is POST as per spec. If you want to verify that the request method is POST, you must explicitly set it in your mock configuration.
Parameters
key
: The key in theapplication/x-www-form-urlencoded
request body.suffix
: The suffix that must appear at the end of the value associated with the key.
Example
Returns
When
: Returns the modified When
object with the new key-value suffix requirement added to the
application/x-www-form-urlencoded
expectations.
form_urlencoded_tuple_suffix_not
Sets a requirement that a key’s value in an application/x-www-form-urlencoded
request body must not end with a specific suffix.
This method sets an expectation that the value associated with a specific key must not end with a specified suffix
in the request body of an application/x-www-form-urlencoded
POST request. The key and the suffix are URL-encoded
as specified by the URL Standard.
Note: The mock server does not automatically verify that the HTTP method is POST as per spec. If you want to verify that the request method is POST, you must explicitly set it in your mock configuration.
Parameters
key
: The key in theapplication/x-www-form-urlencoded
request body.suffix
: The suffix that must not appear at the end of the value associated with the key.
Example
Returns
When
: Returns the modified When
object with the new key-value suffix exclusion requirement added to the
application/x-www-form-urlencoded
expectations.
form_urlencoded_tuple_matches
Sets a requirement that a key-value pair in an application/x-www-form-urlencoded
request body must match specific regular expressions.
This method sets an expectation that the key and the value in a key-value pair must match the specified regular expressions
in the request body of an application/x-www-form-urlencoded
POST request. The key and value regular expressions are URL-encoded
as specified by the URL Standard.
Note: The mock server does not automatically verify that the HTTP method is POST as per spec. If you want to verify that the request method is POST, you must explicitly set it in your mock configuration.
Parameters
key_regex
: The regular expression that the key must match in theapplication/x-www-form-urlencoded
request body.value_regex
: The regular expression that the value must match in theapplication/x-www-form-urlencoded
request body.
Example
Returns
When
: Returns the modified When
object with the new key-value regex matching requirement added to the
application/x-www-form-urlencoded
expectations.