Dynamic Mocking

Uses: Insomnia

Dynamic mocking extends Insomnia’s existing mock server feature by evaluating templates at request time so responses can change based on the incoming request or defined template logic. You configure routes in Insomnia and serve them from Self-hosted mock servers. Headers and status codes remain configured per route, which ensures consistency while response data updates dynamically.

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

For adding random values, Insomnia provides Faker template tags that you can insert anywhere that tags are supported.

Use dynamic mocking to:

  • Serve request-aware responses: Configure a mock route that adapts to request headers and shape the response based on the incoming request. For example, echoing identifiers or switching fields. You manage this for each route.
  • Insert random data with template tags: Use Insomnia’s Faker template tags to generate values like names, emails, timestamps, and UUIDs.

Dynamic capabilities

Use case

Description

Use request data 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 Use simple Liquid conditions to vary the response based on the request.
Only a limited set of Liquid tags are supported for safety.
Generate fake data Insert random but realistic data, such as names, emails, or timestamps.
Use Faker template tags anywhere template tags are supported.
Combine request and fake data Mix request data with generated values for realistic scenarios. For example, include the requester’s ID with random profile data.

Template reference examples

Dynamic mocking in Insomnia supports a limited but powerful set of Liquid template tags and logic controls. These enable variable responses, conditional behavior, and safe data generation.

Faker usage follows Insomnia’s template tag model. You can use Faker functions anywhere template tags are supported to generate realistic mock data like names, emails, or timestamps.

For a complete list of available Faker properties, go to faker-functions.ts.

Liquid logic control

Logic control in dynamic mocking is based on Liquid’s templating language; it only supports a subset of built-in tags for safety and simplicity.

Tag

Description

Reference

assign Creates or updates a variable within the template scope. LiquidJS Assign
if Conditionally renders a block of content when a statement evaluates as true. LiquidJS If
unless Renders a block when a statement evaluates as false; acts as the inverse of if. LiquidJS Unless
raw Prevents Liquid from interpreting enclosed content. Use this to escape template syntax within mock responses. LiquidJS Raw

For additional implementation details and syntax behavior, go to the LiquidJS documentation.

Use data from requests

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

Format to output a variable:

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

Format to define a default value:

{{ 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 template tags to generate random but realistic data in mock responses.

Format to output random data:

{{ faker.randomFullName }}

Self-hosted mocks run the published container image from the repository.

Basic test options

Option

Description

When to use

Send now Immediately send a request to the mock server and display the response in the Response pane. 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 Produce a client-side code snippet that reproduces the current mock request in multiple languages. For example, curl, JavaScript fetch, or Python requests. 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

Option

Description

When to use

Send after delay Schedules the request to execute after a specified delay in milliseconds. The request is queued and sent automatically once the delay expires. 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 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. 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.
Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!