Hello Everyone, I was having little issue in wirem...
# general
k
Hello Everyone, I was having little issue in wiremock to convert url parameter which is coming in string to integer. Example : { "request": { "method": "GET", "urlPattern": "/api/v4/Automation/Get/test/([0-9]+)" }, "response": { "status": 200, "headers": { "Content-Type": "application/json" }, "transformers": ["response-template"], "body": "{\"Status\":200,\"Message\":null,\"data\":{\"id\": {{request.path.[5]}}}}" } } I want to assign last url parameter to id property in body object. Can anyone please me out here.
l
What error are you getting? I am wondering if the templating engine is getting a little confused with all the
}
characters together. This seems to work for me by just adding a bit of space:
Copy code
{
  "request": {
    "method": "GET",
    "urlPattern": "/api/v4/Automation/Get/test/([0-9]+)"
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json"
    },
    "transformers": [
      "response-template"
    ],
    "body": "{\"Status\":200,\"Message\":null,\"data\":{\"id\": {{request.path.[5]}} }}"
  }
}
When I send this request -
curl localhost:8080/api/v4/Automation/Get/test/1234
I get this response:
Copy code
{
  "Status": 200,
  "Message": null,
  "data": {
    "id": 1234
  }
}