【问题标题】:Wiremock Capture path param and return in the response body after "=" symbol onlyWiremock 捕获路径参数并仅在“=”符号后返回响应正文
【发布时间】:2022-01-01 23:49:31
【问题描述】:

我正在尝试使用 WireMock 创建动态模拟。我的网址是这样的:

http://localhost:8080/manage/classids/query1=ns1/query2=id1

然后我想输出为

{ 
   "yourId":"id1"
}

我尝试这样做

{
    "name": "Req_GET",
    "request": {
        "urlPathPattern": "/manage/classids/query1=([a-zA-Z0-9]*)/query2=([a-zA-Z0-9]*)",
        "method": "GET"
    },
    "response": {
        "status": 200,
        "jsonBody": {
            "yourId": "{{request.path.[3]}}"
        },
        "transformers": [
            "response-template"
        ],
        "headers": {
            "Content-Type": "application/json"
        }
    }
}

但我无法在“=”之后拆分响应,它在“/”之后是完整的

{ 
   "yourId":"query2=id1"
}

【问题讨论】:

    标签: json api wiremock wiremock-standalone wiremock-record


    【解决方案1】:

    可以直接使用WireMock的request model引用查询参数

    ...
    "yourId": "{{request.query.query1}}"
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-28
      • 2014-04-12
      相关资源
      最近更新 更多