A scenario answers a path with a sequence of responses: the first call gets step 1, the second gets step 2, and so on. This is useful for flows that change over time, such as polling a payment until it succeeds.
Create a scenario
- Open Scenarios and select New scenario.
- Enter a Name (at least 3 characters) and choose the project.
- Set the Trigger:
- Method: a method, or Any method.
- Path: starts with
/, relative to the project's base path; same patterns as endpoint paths.
- Choose what happens After last step:
- Loop: start again from step 1.
- Once: the last step repeats.
- Open the steps and select Add step. Each step has a name, a status code (100 to 599), headers, a body and an optional delay in milliseconds. Templates work in step bodies.
Example: polling a charge. Trigger GET /charges/:id, mode Once, three steps:
| Step | Status | Body |
|---|---|---|
| 1 | 202 | {"status": "pending"} |
| 2 | 200 | {"status": "processing"} |
| 3 | 200 | {"status": "succeeded"} |
Call it
$ curl -s $URL/payments/charges/ch_1 \
-H "X-Mockhop-Session: test-17"
Call it three times with the same header and you get the three steps in order. From the fourth call on, step 3 repeats.
Sessions
Each session walks through the steps on its own. Mockhop identifies the session from, in this order:
- the
X-Mockhop-Sessionrequest header - the
mockhop_sessioncookie - the client's IP address
The header also works from a browser: mocks allow the request headers your app asks for in a CORS preflight.
Every scenario response carries two headers:
X-Mockhop-Scenario: the ID of the scenario that answeredX-Mockhop-Scenario-Step: the step that was served, for example2/3
Good to know
- While a scenario is active, it answers its trigger before any endpoint on the same path.
- The scenario page shows live sessions. You can reset one session or all of them; a reset session starts again at step 1.
- Sessions that haven't been used for 24 hours are removed automatically.
- Scenarios are part of the Pro, Team and Business plans.
Example use: Mock polling and multi-step flows.