Skip to content

Commit 66cb040

Browse files
yaoweiprcjuliamrchCopilotCopilot
authored
Refine dynamic mock doc (#4817)
* Refine dynamic mock doc. * Update app/_landing_pages/insomnia/mock-servers.yaml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix subject-verb agreement: use "subset" with "is" Agent-Logs-Url: https://github.com/Kong/developer.konghq.com/sessions/8be40d68-4447-4c4c-a3f2-87ae4c7ce415 Co-authored-by: juliamrch <101819212+juliamrch@users.noreply.github.com> --------- Co-authored-by: Julia March <julia.navarro@konghq.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: juliamrch <101819212+juliamrch@users.noreply.github.com>
1 parent bed003e commit 66cb040

2 files changed

Lines changed: 51 additions & 49 deletions

File tree

app/_landing_pages/insomnia/mock-servers.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ rows:
8181
blocks:
8282
- type: text
8383
text: |
84-
Dynamic mocking expands Insomnia’s mock servers with templates that generate context-aware and realistic responses.
85-
Each response is rendered server-side by the mock server using templates with a safe, restricted tag set.
86-
Insomnia also provides **Faker template tags** for generating random names, dates, and other test data at runtime.
84+
Dynamic mocking expands Insomnia’s mock servers with the Liquid template language that generates context-aware and realistic responses.
85+
Each response is rendered server-side by the mock server using Liquid templates with a safe, restricted tag set.
86+
Insomnia also provides faker variables for generating random names, dates, and other test data at runtime.
8787
88-
Dynamic mocking is supported in **self-hosted** mock servers, and powered by the Insomnia **Mockbin** service.
88+
Dynamic mocking is supported in both **cloud-hosted** and **self-hosted** mock servers, and powered by the Insomnia **Mockbin** service.
8989
[Learn more about Dynamic mocking](/insomnia/dynamic-mocking/)
9090
- header:
9191
text: "Frequently asked questions"

app/insomnia/dynamic-mocking.md

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ products:
99
tags:
1010
- mock-servers
1111

12-
description: Use dynamic mocking in Insomnia mock servers to return request-aware responses and realistic mock data with self-hosted mocks.
12+
description: Use dynamic mocking in Insomnia mock servers to return request-aware responses and realistic mock data.
1313

1414
breadcrumbs:
1515
- /insomnia/
@@ -27,15 +27,15 @@ related_resources:
2727
url: /insomnia/template-tags/
2828
---
2929

30-
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.
30+
Dynamic mocking extends Insomnia’s existing mock server feature by evaluating Liquid templates at request time so the response body can change based on the incoming request, and can include randomly generated fake data. You can use the Liquid template language in the Mock Body tab of a mock route in the Insomnia app to define a dynamic response body. Response headers and status codes remain configured per route, which ensures consistency while the response body updates dynamically.
3131

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

34-
For adding random values, Insomnia provides [**Faker template tags**](/insomnia/template-tags/) that you can insert anywhere that tags are supported.
34+
For adding random values, Insomnia provides faker variables that you can insert anywhere in the response body.
3535

3636
Use dynamic mocking to:
37-
- **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.
38-
- **Insert random data with template tags**: Use Insomnia’s Faker template tags to generate values like names, emails, timestamps, and UUIDs.
37+
- **Serve request-aware responses**: Configure 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.
38+
- **Insert random data with faker variables**: Use faker variables to generate values like names, emails, timestamps, and UUIDs.
3939

4040
## Dynamic capabilities
4141

@@ -54,55 +54,25 @@ rows:
5454
- option: Apply conditional logic
5555
description: |
5656
Use simple Liquid conditions to vary the response based on the request.
57-
Only a limited set of Liquid tags are supported for safety.
57+
Only a limited subset of Liquid tags is supported for safety.
5858
- option: Generate fake data
5959
description: |
60-
Insert random but realistic data, such as names, emails, or timestamps.
61-
Use [**Faker template tags**](/insomnia/template-tags/) anywhere template tags are supported.
60+
Insert random but realistic data, such as names, emails, or timestamps using faker variables.
6261
- option: Combine request and fake data
6362
description: |
6463
Mix request data with generated values for realistic scenarios. For example, include the requester’s ID with random profile data.
6564
{% endtable %}
6665
<!-- vale on -->
6766

68-
## Template reference examples
67+
## Template syntax
6968

70-
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.
69+
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:
7170

72-
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.
71+
- `req` — exposes data from the incoming request, including headers, query parameters, path segments, and body.
72+
- `faker` — exposes a set of data generation functions that produce random but realistic values such as names, emails, and timestamps.
7373

74-
For a complete list of available Faker properties, go to [**faker-functions.ts**](https://github.com/Kong/insomnia/blob/develop/packages/insomnia/src/templating/faker-functions.ts).
74+
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.
7575

76-
### Liquid logic control
77-
78-
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.
79-
80-
<!-- vale off -->
81-
{% table %}
82-
columns:
83-
- title: Tag
84-
key: tag
85-
- title: Description
86-
key: description
87-
- title: Reference
88-
key: ref
89-
rows:
90-
- tag: "`assign`"
91-
description: "Creates or updates a variable within the template scope."
92-
ref: "[LiquidJS Assign](https://liquidjs.com/zh-cn/tags/assign.html)"
93-
- tag: "`if`"
94-
description: "Conditionally renders a block of content when a statement evaluates as true."
95-
ref: "[LiquidJS If](https://liquidjs.com/zh-cn/tags/if.html)"
96-
- tag: "`unless`"
97-
description: "Renders a block when a statement evaluates as false; acts as the inverse of `if`."
98-
ref: "[LiquidJS Unless](https://liquidjs.com/zh-cn/tags/unless.html)"
99-
- tag: "`raw`"
100-
description: "Prevents Liquid from interpreting enclosed content. Use this to escape template syntax within mock responses."
101-
ref: "[LiquidJS Raw](https://liquidjs.com/zh-cn/tags/raw.html)"
102-
{% endtable %}
103-
<!-- vale on -->
104-
105-
For additional implementation details and syntax behavior, go to the [**LiquidJS documentation**](https://liquidjs.com/zh-cn/).
10676

10777
### Use data from requests
10878

@@ -132,16 +102,48 @@ You can access values from incoming requests and include them in your mock respo
132102

133103
### Generate random data
134104

135-
Use Faker template tags to generate random but realistic data in mock responses.
105+
Use faker variables to generate random but realistic data in mock responses.
136106

137107
**Format to output random data:**
138108

139109
```liquid
140110
{% raw %}{{ faker.randomFullName }}{% endraw %}
141111
```
142112

143-
{:.info}
144-
> Self-hosted mocks run the published container image from the repository.
113+
For a complete list of available faker variables, go to [**run.js#L218**](https://github.com/Kong/insomnia-mockbin/blob/04134cf81ce29ae7ffcc7ee13e2ecbce70414a96/lib/routes/bins/run.js#L218).
114+
115+
### Liquid logic control
116+
117+
Only the following Liquid tags are supported:
118+
119+
<!-- vale off -->
120+
{% table %}
121+
columns:
122+
- title: Tag
123+
key: tag
124+
- title: Description
125+
key: description
126+
- title: Reference
127+
key: ref
128+
rows:
129+
- tag: "`assign`"
130+
description: "Creates or updates a variable within the template scope."
131+
ref: "[Liquid Assign](https://liquidjs.com/tags/assign.html)"
132+
- tag: "`if`"
133+
description: "Conditionally renders a block of content when a statement evaluates as true."
134+
ref: "[Liquid If](https://liquidjs.com/tags/if.html)"
135+
- tag: "`unless`"
136+
description: "Renders a block when a statement evaluates as false; acts as the inverse of `if`."
137+
ref: "[Liquid Unless](https://liquidjs.com/tags/unless.html)"
138+
- tag: "`raw`"
139+
description: "Prevents Liquid from interpreting enclosed content. Use this to escape template syntax within mock responses."
140+
ref: "[Liquid Raw](https://liquidjs.com/tags/raw.html)"
141+
{% endtable %}
142+
<!-- vale on -->
143+
144+
For additional implementation details and syntax behavior, go to the [**LiquidJS documentation**](https://liquidjs.com/).
145+
146+
## The test options for a mock route in the Insomnia app
145147

146148
### Basic test options
147149

0 commit comments

Comments
 (0)