---
title: Dynamic Mocking
description: Use dynamic mocking in Insomnia mock servers to return request-aware
  responses and realistic mock data.
url: "/insomnia/dynamic-mocking/"
canonical_url: "/insomnia/dynamic-mocking/"
content_type: reference
products:
- Insomnia
tags:
- mock-servers
canonical: true


---

# Dynamic Mocking










Dynamic mocking extends Insomnia’s existing mock server feature. For each request, dynamic mocking renders Liquid templates so responses can include:

- Data from the request (headers, query parameters, path, or body).
- Randomly generated fake data.

## How to use the Liquid template

Use the Liquid template language in the Insomnia app:

1. Open or create a Mock server.
2. Create a new route.
3. Go to the **Mock Body** tab.
4. Define a dynamic response body.

Response headers and status codes remain configured per route, which ensures consistency while the response body updates dynamically.

### Differences from traditional mocks

Traditional mocks return static, predefined payloads, while dynamic mocks generate context-aware, variable outputs:


#### Static
Response behavior: Returns the response body exactly as written.
Example: The Mock Body is `"name": "George"`. Every request to the route returns `George`.

#### Dynamic (random)
Response behavior: Each request evaluates faker expressions in the Mock Body.
Example: The Mock Body contains `{"name": ""}`. Each request returns a different randomly generated name.

#### Dynamic (context-aware)
Response behavior: Expressions in the Mock Body read data from the incoming Collection request.
Example: The Mock Body contains `{"echoed_id": ""}`. A request from a Collection to `<server-url/mock?id=42` returns `{"echoed_id": "42"}`.

#### Mixed
Response behavior: Combines fixed fields with evaluated expressions.
Example: The Mock Body contains `faker.randomFullName` and a fixed `"role": "admin"` field. Each request returns a different name with the role set to `admin`.




For adding random values, Insomnia provides faker variables that you can insert anywhere in the response body.

Use dynamic mocking to:
- **Serve request-aware responses**: Create a mock route that shapes the response body based on the incoming request. For example, echoing identifiers or switching fields based on a query parameter or request body. Only available when running the request from a Collection, where you can copy the mock route URL and input **query parameters** to be echoed.
- **Insert random data with faker variables**: Use faker variables to generate values like names, emails, timestamps, and UUIDs.

## Dynamic capabilities


### Use request data
Description: |
  Access details from the incoming request and reflect them in the mock response. For example, echo a query parameter or include a field from the request body. 
  This makes the mock behave more like a live API.

### Apply conditional logic
Description: |
  Use simple Liquid conditions to vary the response based on the request.  
  Only a limited subset of Liquid tags is supported for safety.

### Generate fake data
Description: Insert random but realistic data, such as names, emails, or timestamps using faker variables.

### Combine request and fake data
Description: Mix request data with generated values for realistic scenarios. For example, include the requester’s ID with random profile data.




## Template syntax

Dynamic mocking uses [**Liquid**](https://liquidjs.com/tutorials/intro-to-liquid.html) as its templating language. Mock response bodies are rendered as Liquid templates at request time, with two built-in variables available:

- `req` — exposes data from the incoming request, including headers, query parameters, path segments, and body.
- `faker` — exposes a set of data generation functions that produce random but realistic values such as names, emails, and timestamps.

To keep templates safe and predictable, only a limited subset of Liquid tags is supported for logic control. For filters, only the [default filter](https://liquidjs.com/filters/default.html) is supported.




### Use data from requests

You can access values from incoming requests and include them in your mock responses.

**Format to output a variable:**

```liquid
{{ req.headers['Content-Type'] }}
{{ req.body.name }}
```

**Format to define a default value:**

```liquid
{{ req.body.name | default: "George" }}
```

**Available variables**

- `req.headers.*` — Reference a specific request header  
- `req.queryParams.*` — Reference query parameters in the URL  
- `req.pathSegments[*]` — Reference specific segments of the URL path  
- `req.body` — Returns the full request body (only when the body is not a binary stream)  
- `req.body.*` — When the content type is `application/json`, `application/x-www-form-urlencoded`, or `multipart/form-data`, Insomnia parses the body and exposes each field  

### Generate random data

Use faker variables to generate random but realistic data in mock responses.

For a complete list of available faker variables, check the [faker variables list](/insomnia/faker-variables).

**Format to output random data:**

```liquid
{{ faker.<variable-name> }}
```

For example:

```liquid
{{ faker.randomFullName }}
```

### Liquid logic control

Only the following Liquid tags are supported:


#### `assign`
Description: Creates or updates a variable within the template scope.
Reference: [Liquid Assign](https://liquidjs.com/tags/assign.html)

#### `if`
Description: Conditionally renders a block of content when a statement evaluates as true.
Reference: [Liquid If](https://liquidjs.com/tags/if.html)

#### `unless`
Description: Renders a block when a statement evaluates as false; acts as the inverse of `if`.
Reference: [Liquid Unless](https://liquidjs.com/tags/unless.html)

#### `raw`
Description: Prevents Liquid from interpreting enclosed content. Use this to escape template syntax within mock responses.
Reference: [Liquid Raw](https://liquidjs.com/tags/raw.html)




For additional implementation details and syntax behavior, go to the [**LiquidJS documentation**](https://liquidjs.com/).

## The test options for a mock route in the Insomnia app

### Basic test options

#### Send now
Description: Immediately send a request to the mock server and display the response in the Response pane.
When to use: Use this option for quick validation that your mock routes, dynamic templates, or environment variables resolve correctly. Ideal during early setup or after modifying a mock definition.

#### Generate client code
Description: Produce a client-side code snippet that reproduces the current mock request in multiple languages. For example, `curl`, JavaScript `fetch`, or Python `requests`.
When to use: Use this when you want to share or automate the mock request outside Insomnia. For example, add it to test scripts, CI jobs, or SDK examples.



### Advanced test options

#### Send after delay
Description: Schedules the request to execute after a specified delay in milliseconds. The request is queued and sent automatically once the delay expires.
When to use: Use this option to simulate **network latency**, **rate-limited APIs**, or **background task timing**. It helps validate client-side behavior when responses are delayed.

#### Repeat on interval
Description: Sends the same request repeatedly on a fixed interval until stopped. Each cycle executes independently, allowing you to observe variable or time-sensitive responses from the dynamic mock.
When to use: Use this to test **dynamic responses**, such as mocks that use Faker data, timestamp generation, or conditional logic. It’s also useful for load, polling, or long-running integration tests.




## Related Resources

- [Mocks](/insomnia/mock-servers/)

- [Self-hosted mocks](/insomnia/self-hosted-mocks/)

- [Storage options](/insomnia/storage/)

- [Requests](/insomnia/requests/)

- [Template tags](/insomnia/template-tags/)

