Skip to content

Response strategies ​

An endpoint can hold several responses. The strategy, chosen under How should this endpoint respond?, decides which one is sent for each request.

StrategyWhich response is sentTypical use
Single responseAlways the firstOne fixed answer
Conditional rulesThe first whose conditions all match the requestSuccess and error cases from one endpoint
Sequence (round-robin)Each in turn, one per requestRetries and polling
Random / weightedOne picked at random, by weightA flaky service

Changing the strategy does not delete anything. Responses, conditions and weights are kept; the strategy only decides which of them are used. Point at a strategy button to read how it works.

Single response ​

The endpoint always sends its first response. Any other responses on the endpoint are ignored until you choose another strategy.

Example: a health check.

  • Endpoint: GET /health
  • Response: status 200, body {"status": "ok"}

Every call gets the same 200.

To add a second response from here, select Add another response (switches to conditional rules) under the card.

Conditional rules ​

Responses are checked from top to bottom. The first one whose conditions all match the request is sent. A response with no conditions is the fallback: it is sent when nothing else matches.

An endpoint using Conditional rules with a default response
  1. 1Conditional rules — The selected strategy.
  2. 2Add response — Adds another response to the endpoint.
  3. 3Default response (fallback) — This response has no conditions, so it is the fallback.
  4. 4Add condition — Adds a condition and makes the response selective.

Example: a product lookup that can fail.

Endpoint: GET /products/:id

OrderLabelConditionStatus
1Not foundPath param id equals 999404
2Out of stockQuery param stock equals none409
3Foundnone (fallback)200
RequestResponse sent
GET /products/999Not found, 404
GET /products/5?stock=noneOut of stock, 409
GET /products/5Found, 200

Conditional rules lists every source and operator and walks through the sample login endpoint.

Sequence (round-robin) ​

The responses are sent in order, one per request. After the last one, the endpoint starts again from the first. Each card shows its position number.

Example: fail twice, then succeed. This is the Retry sequence template.

Endpoint: GET /retry

PositionLabelStatus
1Attempt 1 — fail503
2Attempt 2 — fail503
3Attempt 3 — success200
CallStatus
1st503
2nd503
3rd200
4th503 (the sequence starts over)

Use it to check that your app retries a failed call, or to simulate a job that reports pending a few times and then done.

Things to know:

  • One counter per endpoint. The position is shared by every client. If two apps call the endpoint, they take turns through the same sequence.
  • The position is not saved. It starts from the first response again when you reopen Mock Studio.
  • To repeat a status several times in a row, Duplicate the response.

Random / weighted ​

One response is picked at random for each request. Each response has a Weight; a higher weight makes it more likely. The chance of a response is its weight divided by the total of all weights. The minimum weight is 1.

Example: a service that fails about one time in five. This is the Flaky service (random errors) template.

Endpoint: GET /flaky

LabelWeightStatusChance
Success82008 ÷ 10 = 80%
Server error25002 ÷ 10 = 20%

Over many calls about 80% succeed. The choice is random each time, so ten calls will not give exactly eight successes.

Weights are relative. 8 and 2 behave the same as 4 and 1. Three responses with weights 3, 1 and 1 are chosen 60%, 20% and 20% of the time.

Use this strategy with Flows to see how your app or a test suite copes with intermittent errors. For exact, repeatable failures, use Sequence instead.

Combine a strategy with other features ​

  • Every response can use placeholders, so a rule-selected 404 can still echo the requested id.
  • Every response can have its own delay override or fault. A sequence of normal, slow, dropped is a quick resilience test.
  • The Live section shows the label of the response that was sent, so you can confirm the strategy picked the one you expected.

Check yourself ​

QuizResponse strategies

Question 1 of 6

GET /products/:id uses Conditional rules with these responses, top to bottom. Which is sent for GET /products/999?stock=none?

1. Not found     Path param id equals 999       404
2. Out of stock  Query param stock equals none  409
3. Found         (no conditions)                200
Score: 0

Next steps ​