-
Notifications
You must be signed in to change notification settings - Fork 6
Mock Matching Approach
The mock matching algorithm mirrors much of Postman's supplied approach - https://learning.postman.com/docs/designing-and-developing-your-api/mocking-data/matching-algorithm/
The mock server will accept requests that use any path, with any HTTP method. The service then searches the list of responses in the supplied collection that potentially match the inbound request, and it then returns the closest match based based on a series of factors.
The following steps are used to find the best matched response:
- HTTP Method - Filter out any responses from the collection that don't match the inbound HTTP method.
- x-mock Headers - If an x-mock header was used, filter for only responses that match this header.
- URL Match - Filter for responses that match the URL supplied in the request. This matching looks for path matches as well as query parameters and partial matches.
-
Match Headers - If the
x-mock-match-request-headers
modifier is used, validate that the responses contain the request header specified. -
Match Body - If the
x-mock-match-request-body
modifier is used, validate that the responses contain a matching request body.
If at the end of this no responses are left, the service will return a 404 Not Found. Otherwise, the best matched response based on a score will be returned.
If an x-mock
header is provided and the collection has multiple responses that match, currently the service will simply return the first one found. To better match the Postman approach it should first order the list of responses that are left by ID and then return the first 2xx response. If none can be found it can then return the first mock response found.