Wiremock Capture path param and return in the response body after "=" symbol only

599 Views Asked by At

I am trying to create dynamic mocks using WireMock. My URL is like :

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

then I want output as

{ 
   "yourId":"id1"
}

I try do like this way

{
    "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"
        }
    }
}

but I am not able to split response after "=" it is coming whole after "/"

{ 
   "yourId":"query2=id1"
}
1

There are 1 best solutions below

0
On

You can reference the query parameter directly using WireMock's request model

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