You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: app/insomnia/dynamic-mocking.md
+47-45Lines changed: 47 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ products:
9
9
tags:
10
10
- mock-servers
11
11
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.
13
13
14
14
breadcrumbs:
15
15
- /insomnia/
@@ -27,15 +27,15 @@ related_resources:
27
27
url: /insomnia/template-tags/
28
28
---
29
29
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.
31
31
32
32
Traditional mocks return static, predefined payloads, while dynamic mocks generate context-aware, variable outputs.
33
33
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.
35
35
36
36
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.
39
39
40
40
## Dynamic capabilities
41
41
@@ -54,55 +54,25 @@ rows:
54
54
- option: Apply conditional logic
55
55
description: |
56
56
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.
58
58
- option: Generate fake data
59
59
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.
62
61
- option: Combine request and fake data
63
62
description: |
64
63
Mix request data with generated values for realistic scenarios. For example, include the requester’s ID with random profile data.
65
64
{% endtable %}
66
65
<!-- vale on -->
67
66
68
-
## Template reference examples
67
+
## Template syntax
69
68
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:
71
70
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.
73
73
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.
75
75
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."
For additional implementation details and syntax behavior, go to the [**LiquidJS documentation**](https://liquidjs.com/zh-cn/).
106
76
107
77
### Use data from requests
108
78
@@ -132,16 +102,48 @@ You can access values from incoming requests and include them in your mock respo
132
102
133
103
### Generate random data
134
104
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.
136
106
137
107
**Format to output random data:**
138
108
139
109
```liquid
140
110
{% raw %}{{ faker.randomFullName }}{% endraw %}
141
111
```
142
112
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."
0 commit comments