For each route, multiple responses can be defined (status, body, and headers) and triggered using a set of rules.
To add a new response to your route, click on the "plus" icon next to the responses list:
You can also duplicate an existing route response by clicking on the "copy" icon on the right:
There is always at least one response when you create a new route. You can modify it and add more responses. But you can never delete the last route response.
Without rules or when a request does not match the one you defined, the default response will always be the first one in the list. You can easily change the default response by reordering the responses menu with a drag and drop:
Mockoon can serve the route responses randomly (200, 500, 404) to simulate an unpredictable behavior.
To activate this option, click on the "shuffle" icon next to the response list:
You can define an unlimited number of rules for each route. At each request, Mockoon will read each route response rules and will return the response which contains the first matching rule(s). The rules are interpreted by default as follow: [rule OR rule] OR [rule OR rule]
the brackets symbolizing each route response.
To add a new rule to a response, go to the route response's Rules tab and fill the fields:
Inside a route response, rules are interpreted by default with the OR operator. When you have more than one rule in a route response, you can easily switch the operator applied when interpreting the rules, by clicking on the OR
/AND
buttons at the left of the rules:
Rules have three parts:
In the dropdown menu you can choose between:
Content-Type
is either application/json
or application/x-www-form-urlencoded
).Depending on the target, the way to access properties may be different:
users.0.name
for JSON content or a single field for form data.Accept
or Content-Type
.:userId
becoming userId
.filter
or a path if the query string field is an object filter.primary
.For body and query string, if the property is an array, Mockoon will automatically check in the array if at least one item matches the value.
You can either set a simple text value like "expected value" or any kind of regex. To use a regex, write it without the leading and trailing slashes and tick the checkbox on the right.
Examples:
primary|secondary
, ^user1-9
, UTF-.*
.
You can also test for empty values with the following regex: ^$|\s+
.
Or follow us on Twitter
Follow @GetMockoon