Hello,
What I'm trying to achieve seemed pretty simple in theory but it has been giving me a big headache.
I want to return in the response the same exact JSON payload that I've received in the request.
Below is what I've been trying.
If I use "body": "{{request.body}}" I get an encoded xml representation of my input.
I've tried looking into handlebars and tried few variations of the following:
"body": "{{json context [view=\"request.body\"] [escapeHTML=false] [pretty=false]}}",
In this case I get a 500 response and Wiremock does not print anything in the logs (in verbose mode).
Is it possible to return whatever payload was sent in the request?
Thanks in advance!
Complete mapping file:
{
"request": {
"method": "POST",
"urlPattern": "/v1/.*/configurations/",
"bodyPatterns": [ {
"matches" : "^((?!error).)*$"
} ]
},
"response": {
"status": 201,
"body": "{{request.body}}",
"transformers": ["response-template"],
"headers": {
"Content-Type": "application/json"
}
}
}
Hi, just had the same issue. Seems like wrapping request.body like this {{{request.body}}} works (no escaping). Haven't found any official documentation on this, but found this: https://groups.google.com/forum/#!topic/wiremock-user/2rD0e6kUdE0
The {{{ ... }}} non-escaping syntax is standard Handlebars: http://handlebarsjs.com/#html-escaping
Most helpful comment
Hi, just had the same issue. Seems like wrapping
request.bodylike this{{{request.body}}}works (no escaping). Haven't found any official documentation on this, but found this: https://groups.google.com/forum/#!topic/wiremock-user/2rD0e6kUdE0