> ## Documentation Index
> Fetch the complete documentation index at: https://docs.godizzy.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Mock Responses

> Configure deterministic mock responses for your routing rules, use templates to echo request data, and roll back to any prior version.

A mock response is what GoDizzy returns to your agent or client instead of forwarding the request to your target endpoint. You configure the status code, headers, body, and a latency range — and GoDizzy serves that fixture every time the rule matches, with no outbound traffic.

## Configure a mock response

<Steps>
  <Step title="Open your route collection">
    In the dashboard, navigate to **Routes**, select your environment, and open the route collection that contains the rule you want to configure.
  </Step>

  <Step title="Create or select a routing rule">
    Click **Add Rule** to create a new rule, or click an existing rule to edit it. Set the HTTP method and path pattern for the rule to match (for example, `POST` and `/api/search`).
  </Step>

  <Step title="Set the action to Mock">
    In the rule editor, set the **Action** to **Mock**. If the rule was previously set to Proxy, the toggle on the rule card also switches between the two modes — flip it to enable mocking without opening the full editor.
  </Step>

  <Step title="Enter the status code">
    Enter the HTTP status code GoDizzy should return. Use any valid code: `200` for success, `429` for rate-limit simulation, `500` for error scenarios, and so on.
  </Step>

  <Step title="Add response headers (optional)">
    Provide response headers as a JSON object. Each key is a header name and each value is the header value string.

    ```json theme={null}
    {
      "Content-Type": "application/json",
      "X-Request-Id": "{{$randomUUID}}"
    }
    ```

    <Note>
      Template variables such as `{{$randomUUID}}` work in header values. See the [Template variables](#template-variables) section below for the full list.
    </Note>
  </Step>

  <Step title="Write the response body">
    Enter the response body as a JSON string. This is the exact payload GoDizzy returns to the caller.

    ```json theme={null}
    {
      "results": [
        { "id": "{{$randomUUID}}", "title": "Annual report Q4", "score": {{$randomInt(70,99)}} },
        { "id": "{{$randomUUID}}", "title": "Budget forecast", "score": {{$randomInt(50,69)}} }
      ],
      "query": {{$reqBody['q']}},
      "total": 2,
      "retrieved_at": "{{$isoTimestamp}}"
    }
    ```
  </Step>

  <Step title="Set the latency range">
    Enter a **Min latency (ms)** and **Max latency (ms)**. GoDizzy picks a random value in that range before responding. Set both to `0` for an immediate response. See the [Latency Injection](/guides/latency-injection) guide for more detail.
  </Step>

  <Step title="Save">
    Click **Save**. GoDizzy creates a new version of the mock response. Your previous configuration is preserved in version history and can be restored at any time.
  </Step>
</Steps>

## Template variables

Mock response bodies and headers support template placeholders that GoDizzy expands at response time. You can reference random values, timestamps, and fields from the incoming request body.

<AccordionGroup>
  <Accordion title="Random values">
    | Syntax                       | Description                                                           | Example                                  |
    | ---------------------------- | --------------------------------------------------------------------- | ---------------------------------------- |
    | `{{$randomUUID}}`            | RFC 4122 UUID v4, unique per response                                 | `"id": "{{$randomUUID}}"`                |
    | `{{$randomInt(a,b)}}`        | Integer between `a` and `b` inclusive — omit quotes for a JSON number | `"score": {{$randomInt(0,100)}}`         |
    | `{{$randomAlphaNumeric(n)}}` | `n` characters from A–Z, a–z, 0–9                                     | `"token": "{{$randomAlphaNumeric(16)}}"` |
    | `{{$randomBoolean}}`         | `true` or `false` — omit quotes for a JSON boolean                    | `"ok": {{$randomBoolean}}`               |
    | `{{$randomHex}}`             | 16-character lowercase hex string                                     | `"hash": "{{$randomHex}}"`               |
    | `{{$randomHex(n)}}`          | `n`-character lowercase hex (1–256)                                   | `"hash": "{{$randomHex(32)}}"`           |
  </Accordion>

  <Accordion title="Time and date">
    | Syntax              | Description                                                   | Example                       |
    | ------------------- | ------------------------------------------------------------- | ----------------------------- |
    | `{{$isoTimestamp}}` | UTC instant in ISO 8601 format — use inside string quotes     | `"at": "{{$isoTimestamp}}"`   |
    | `{{$date}}`         | `YYYY-MM-DD` in UTC — use inside string quotes                | `"day": "{{$date}}"`          |
    | `{{$unixSeconds}}`  | Seconds since Unix epoch — omit quotes for a JSON number      | `"created": {{$unixSeconds}}` |
    | `{{$unixMs}}`       | Milliseconds since Unix epoch — omit quotes for a JSON number | `"ts": {{$unixMs}}`           |
  </Accordion>

  <Accordion title="Request body fields">
    `{{$reqBody['key']}}` expands to the value of a top-level field in the incoming JSON body. A missing key or a non-JSON body expands to JSON `null`.

    ```json theme={null}
    {
      "echo": {{$reqBody['message']}},
      "user_id": {{$reqBody['userId']}}
    }
    ```

    <Warning>
      `$reqBody` is only available when the rule's HTTP method is `POST`, `PUT`, or `PATCH`. It is not available for `GET`, `DELETE`, or wildcard (`*`) rules. It also cannot be used in response headers — only in the body.
    </Warning>
  </Accordion>
</AccordionGroup>

## Switching between mock and proxy

You do not need to open the rule editor to switch a rule's behavior. Each rule card has a **toggle** in the rule list view:

* **Toggle on (Mock)** — GoDizzy returns the configured mock response.
* **Toggle off (Proxy)** — GoDizzy forwards the request to the collection's target endpoint.

The toggle directly changes the rule's action. Switching to proxy does not delete your mock response configuration — it is preserved and takes effect again the moment you toggle back to mock.

## Version history and rollback

Every time you save changes to a mock response, GoDizzy creates a new immutable version. Your previous configuration is never overwritten.

<Steps>
  <Step title="Open version history">
    On the rule detail page, click **View History**. The history panel lists every version with the timestamp and the email address of the team member who made the change.
  </Step>

  <Step title="Inspect a prior version">
    Click any version to view its full configuration: status code, headers, body, and latency range.
  </Step>

  <Step title="Revert">
    Click **Revert to this version** on the version you want to restore. GoDizzy creates a new version with the content of the selected prior version — it does not delete the intervening history.
  </Step>
</Steps>

<Tip>
  Revert is non-destructive. Reverting to version 3 while you are on version 7 creates version 8 — which is a copy of version 3. Your full edit history remains intact.
</Tip>

## Example: simulating a rate-limited response

```json theme={null}
{
  "error": {
    "code": "RATE_LIMITED",
    "message": "Too many requests. Retry after {{$randomInt(10,60)}} seconds.",
    "retry_after": {{$randomInt(10,60)}},
    "request_id": "{{$randomUUID}}"
  }
}
```

Set the status code to `429` and configure a latency range of `200`–`800` ms to simulate a realistic throttled API response your agent needs to handle gracefully.
