Multiple responses


For each route, multiple responses can be defined (status, body, and headers) and triggered using a set of rules. 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.

 Adding or duplicating a response

To add a new response to your route, click on the "plus" icon next to the responses list:

Click on the icon to add a new response

You can also duplicate an existing route response by clicking on the "copy" icon on the right:

Click on the copy icon to duplicate a response

Everything will be copied to the new response: documentation, file/body, headers and rules.

 Route responses precedence

Route responses order define the order in which the rules are interpreted. You can easily change the default response by reordering the responses menu with a drag and drop:

Reorder route responses

 Default route response

Without rules or when a request does not match the one you defined, the default response will always be the one marked with the blue flag. You can easily change the default response by clicking on the grey flags in the menu:

Define a new default route response

 Random route response

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:

Random route responses

 Sequential route response

Mockoon can serve the route responses sequentially (200 → 500 → 404). Mockoon will serve all the responses one after the other and restart at the beginning. The sequence is reset when restarting the server.

To activate this option, click on the "repeat" icon next to the response list:

Sequential route responses

 Fallback mode

When the fallback mode is enabled, Mockoon will automatically pass the request to the proxy (or the next route, see below) when none of the responses' rules match.

To activate this option, click on the "fallback" icon next to the response list:

fallback mode responses

Behind the scene, the server will automatically jump to the next route in the order they were declared and, ultimately, to the proxied server. It allows to create complex setups where a wildcard or parameterized route contains rules to protect the access to other routes:

GET /users/* --> Authorization header required
GET /users/:id --> No rules