Is concat an in built String helper function avail...
# help
r
Is concat an in built String helper function available that can be used in response templating ? Could not see this here - https://docs.wiremock.io/response-templating/string-helpers/ or join is the function that should be used to perform concatenation.
l
I haven’t looked at
join
before today but I am not sure it is the helper you are looking for. It looks like it uses the last parameter as the separator between the other parameters passed in. For example, this template fragment generates
Copy code
"foo": "{{join 'Foo' 'Bar' 'Baz'}}",
Generates this result:
Copy code
"foo": "FooBazBar",
I get an error when I try and pass in an empty string as the last parameter which would have been a nice solution. Can you give us a little more context as to what you are trying to achieve to see if we can help find a solution ? Can you share your mapping and a request to use with it ?
For example, if your use case is simple and you are just trying to concat two values together you could try something like this: With a request like this:
Copy code
{
  "first": "Hello",
  "second": "World"
}
Using this mapping file:
Copy code
{
  "name": "concat",
  "request": {
    "url": "/concat",
    "method": "GET"
  },
  "response": {
    "status": 200,
    "jsonBody": {
      "result": "{{jsonPath request.body '$.first'}} {{jsonPath request.body '$.second'}}"
    },
    "headers": {
      "Content-Type": "application/json"
    },
    "transformers": [
      "response-template"
    ]
  }
}
It should generate a result like this:
Copy code
{
  "result": "Hello World"
}
No special helper needed with this example.
r
Thanks a lot @Lee Turner for the guidance. I received a reply from Tom in a previous thread that I had initiated in this context . My use case is listed there. I was trying to change the offset in date at runtime .
l
Ah, nice. Glad you got it sorted. Maybe we should look at loading the concat helper in wiremock.
👍 1