Define multiple responses for each route

Multiple responses can be defined for each route with different body, headers and status. They are triggered with rules.

Get Mockoon latest version and start mocking!

Download

Since v1.5.0, you can define multiple responses for each route and trigger them using a set of rules.

Default route response

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:

Reorder route responses

Defining rules

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. There is no logic between the rules. You can read them like this: [rule OR rule] OR [rule OR rule] the brackets symbolizing each route.

Rules have three parts:

Add route response rules

  1. Target

In the dropdown menu you can choose between:

  • a property value in a JSON or form data body (if request's Content-Type is either application/json or application/x-www-form-urlencoded).
  • the value of a header.
  • the value of a route param.
  • the value of a query string field.

  1. Property name or path

Depending on the target, the way to access properties may be different:

  • body: access a property value using a path (based on NPM package object-path) like users.0.name for JSON content or a single field for form data.
  • headers: a header name like Accept or Content-Type.
  • route param: a route param name without the colon (":"), :userId becoming userId.
  • query string: either provide a property name like 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.

  1. 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-.*

Join Mockoon's mailing list to receive latest updates

Or follow us on Twitter