Skip to content

Return a sequence of responses

Before you begin

Role
Editor or higher.
You need
  • A mock

A response sequence lists steps, and each step names one of the mock’s responses: the first request gets the first step’s response, the second request the second’s, and so on. This page builds “fail twice, then succeed”: two steps that both name a 503 response, then one that names a 200 and keeps answering.

  1. Open the mock from the project’s Mocks tab.

  2. Under What it answers, make the two responses the sequence uses. Edit the open one: enter Unavailable as its Response name and enter 503 as its Status code. Select Response to add a second, and give it the name Success, a 200 Status code and the body of the successful answer.

  3. Open How a response is chosen and, beside Answer with, select A sequence. The steps appear under it, each with a Response for step choice.

  4. Choose Unavailable for Step 1 and for Step 2. Select Add a step, and choose Success for Step 3.

  5. Under After the last step, choose Keep answering with the last.

  6. Select Save mock.

A response may be used by several steps, as Unavailable is here, so its body is written once. Use the arrow buttons beside a step to move it, and the cross to remove it.

After the last step The fourth request here gets Suits
Start over from the first The first step’s response Behaviour that cycles, such as alternating answers
Keep answering with the last The last step’s response Failing then recovering, a job that finishes
  1. Open the project’s Scenarios tab.

  2. Select Reset all.

Between test runs, do the same without the app: mockhub scenarios reset from a terminal or a pipeline, for the project in mockhub.yaml, with --env <name> to choose the target or --project <id> to name another project, or reset_scenarios from an AI assistant connected over MCP. Both need the Editor role, and a machine token may run them; see Reset from the CLI or an AI assistant.

How this mock responds reads the steps in order, such as Unavailable → Unavailable → Success, followed by “keep answering with the last”. After you save, the first two requests to the mock get 503, and every request after them gets 200. Each request log says which step answered, such as Step 2 of the mock’s sequence; see Read request logs.

Reset all, mockhub scenarios reset and reset_scenarios put every sequence in the project back to its first step, and every scenario back to its start; see Inspect and reset scenario state.

  • A sequence holds from two to ten steps, and a mock up to 50 responses. Add a step is unavailable at ten, and removing a step at two.
  • A mock with a sequence has no default response and takes no request override: a request that sends X-MockHub-Response is refused and does not move the sequence.
  • Each mock has one place in its sequence, shared by every caller. Two clients calling the same mock take their turns from the same sequence.
  • A mock with a sequence cannot also be attached to a scenario. Choosing A sequence removes an attachment, and MockHub says “Scenario attachment removed”.
  • In Try it, Preview this response renders the response you have open. Which response a request gets starts a copy at Initial sequence step and says which step the next request would get, without moving the live sequence.
  • In the Record everything gateway mode, sequences do not run; see Gateway modes.
  • MockHub keeps the place in a sequence, also while the mock is inactive. After seven days without a request to the mock, the sequence starts again from its first step.
  • Editing a response’s status code, headers or body keeps the place. Changing which responses the steps name, their order or their number, changing After the last step, or choosing A sequence after the mock was saved with A default response, starts the sequence from its first step, and so does restoring a version that differs in the same way. Renaming a response keeps the place.
  • A turn is spent once the mock has taken it, even when the answer never reaches the caller, as after a dropped connection. When MockHub cannot read or save the place, the mock answers 503 with Scenario unavailable rather than guessing a response.
  • Choosing A default response again keeps the responses and makes one of them the default, which you choose before you save.
  • A response a step names cannot be deleted until the steps no longer name it.

Report a problem with this page