Request Matching
Mimicrab uses a powerful matching engine to identify which mock response to serve based on the incoming request.
Matching Criteria
A request must satisfy all defined conditions in an expectation to match.
HTTP Method
Matches the exact HTTP method (e.g., GET, POST).
Path
Mimicrab supports flexible path matching, including static paths, parameterized segments, and wildcards.
- Static Match: Matches the exact path.
- Example:
/api/v1/users
- Example:
- Parameterized Match: Use
:nameto capture path segments.- Example:
/books/:id/authormatches/books/123/authorand/books/abc/author. - Captured segments can be used in Templating via
{{path[index]}}.
- Example:
- Wildcard Match: Use
*to match any characters.- Prefix Wildcard:
*/booksmatches/path/to/books. - Suffix Wildcard:
/api/*matches/api/v1/usersand/api/v2/posts. - Middle/Segment Wildcard:
/static/*/main.jsmatches/static/v1/main.js.
- Prefix Wildcard:
Headers
Matches if the request contains all specified headers with their corresponding values.
Body (JSON)
Matches if the request body contains all key-value pairs specified in the condition. Mimicrab supports matching nested JSON structures.
Example Condition:
{
"user": {
"role": "admin"
}
}
This will match any request body that has a user object with a role set to admin, regardless of other fields.