Skip to content

Commit 51cc1ca

Browse files
authored
feat: add request payload conditional response (#798)
Co-authored-by: rick <[email protected]>
1 parent 96f2f32 commit 51cc1ca

File tree

5 files changed

+949
-863
lines changed

5 files changed

+949
-863
lines changed

docs/site/content/zh/latest/tasks/mock.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,35 @@ items:
195195
{{end}}
196196
```
197197

198+
下面是一个根据请求 Payload 给出不同响应的例子:
199+
200+
```yaml
201+
items:
202+
- name: createBook
203+
request:
204+
path: /v1/books
205+
method: POST
206+
body: |
207+
{
208+
"size": "big"
209+
}
210+
response:
211+
body: |
212+
{{if eq (fromJson .Param._payload).size "big"}}
213+
{
214+
"name": "big book"
215+
}
216+
{{else if eq (fromJson .Param._payload).size "small"}}
217+
{
218+
"name": "small book"
219+
}
220+
{{else}}
221+
{
222+
"name": "unknown book"
223+
}
224+
{{end}}
225+
```
226+
198227
## 代理
199228

200229
在实际情况中,往往是向已有系统或平台添加新的 API,此时要 Mock 所有已经存在的 API 就既没必要也需要很多工作量。因此,我们提供了一种简单的方式,即可以增加**代理**的方式把已有的 API 请求转发到实际的地址,只对新增的 API 进行 Mock 处理。如下所示:

0 commit comments

Comments
 (0)