![](/img/trans.png)
[英]Puppeteer request interception best practice for multiple responses to the same endpoint
[英]using stubby multiple responses for the same patch request endpoint
這是我在 data.yaml 中的補丁請求映射
request:
url: ^/api/test
method: PATCH
headers:
Content-Type: application/json
response:
headers:
Content-Type: application/json
status: 200
file: response/test-1.json
api 路徑 api/test 是一個 PATCH 請求,它在其主體 {testVar: "1111"} 中接受單個請求參數
我需要實現的是當請求參數為 {testVar: "1111"} -> 當請求參數為 {testVar: "2222"} 時調用 response/test-1.json -> 調用 response/test-2.json
如何實施?
我嘗試了查詢參數、請求參數等,但沒有成功
閱讀:
這里的想法是:
在您的POST
/ PATCH
請求負載中,您可以將參數之一指定為正則表達式,例如: {"testVar": "(.*)"}
。 匹配后的正則表達式標記(即: (.*)
的值(.*)
可用作response
配置的替換標記。 換句話說,您應該能夠根據需要加載相應的 JSON 文件。
但是,為了讓您更輕松,請嘗試以下 YAML 配置:
- request:
method: PATCH
url: ^/api/test
headers:
content-type: application/json
post: >
{"testVar": "(.*)"}
response:
headers:
content-type: application/json
status: 200
file: response/test-<% post.1 %>.json
讓我知道以上是否適合您。 作為參考,我在以下 PR 中測試了上述配置: https : //github.com/azagniotov/stubby4j/pull/280
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.