Response Variants#
A stub can define several possible responses with a responses[] list instead of a single response. This lets you simulate flaky or varied third-party behavior: mostly success, sometimes an error, occasionally a timeout.
id: flaky-webhook
method: POST
path: /webhooks/payment
responses:
- status_code: 200
body: '{"status":"completed","transaction_id":"txn_12345"}'
weight: 80
- status_code: 400
body: '{"error":"insufficient_funds"}'
weight: 15
- status_code: 500
body: '{"error":"internal_error"}'
weight: 5
delay: 2sSend the same request several times and you’ll see roughly: 80% succeed, 15% get a 400, 5% get a slow 500.
for i in 1 2 3 4 5 6 7 8 9 10; do
curl -s -o /dev/null -w "%{http_code}\n" -X POST http://localhost:8080/webhooks/payment
done
# ~ 200 200 200 200 200 200 200 400 200 500Selection Logic#
| Condition | Behavior |
|---|---|
Only response (no responses[]) | Always returns the singular response. |
responses[] with weight | Weighted random selection. |
responses[] without weight | Round-robin rotation, cycled in order. |
Per-Variant Options#
Each variant supports everything the singular response supports, independently:
status_code— HTTP status (default 200)body— response bodyheaders— response headersdelay— simulated latencyecho— echo modetemplate— template mode
Use Cases#
- Retry testing — verify your client retries on
5xxand backs off. - Error handling — confirm error paths show the right messages.
- Timeout behavior — the slow
500variant above exercises both timeout and error handling at once.
Also See#
- stubs/flaky-webhook.yaml — the shipped example stub.
- Delays — per-variant latency.