Hi everyone, could you help me? (sorry for my bad ...
# help
c
Hi everyone, could you help me? (sorry for my bad english) I need to do something like this: mapping:
Copy code
{
  "request": {
    "method": "POST",
    "url": "/api/endpoint"
  },
  "response": {
    "status": 200,
    "transformers": [
      "response-template"
    ],
    "bodyFileName": "response.json",
    "headers": {
      "Content-Type": "application/json"
    }
  }
}
response.json
Copy code
{
  "message": "Hello, {{request.body.message}}!",
  "status": 200
}
I need this response:
Copy code
{
  "message": "Hello, Carlos!",
  "status": 200
}
but I get this:
Copy code
{
  "message": "Hello, {{request.body.message}}!",
  "status": 200
}
request body:
Copy code
{
  "message": "Carlos"
}
What's wrong? Is it possible? wiremock standalone 3.0.1 java -jar wiremock-standalone-3.0.1.jar --port 8282 --verbose Linux server Thanks a lot!!
t
Hi @Carlos Villar, try adding
--local-response-templating
to your startup params
c
I tried, and now I get this:
Is it ok?
Copy code
{{request.body.message}}
extra info: when I put only {{request.body}}, y get this:
a
Using
{{request.body.foo}}
isn’t recommended -> https://wiremock.org/docs/response-templating/#the-request-model
request.body
- Request body text (avoid for non-text bodies)
Instead, we’ll need to use the JSON helpers to make this a little easier. https://wiremock.org/docs/response-templating/#jsonpath-helper Something like the following should work:
Copy code
{{jsonPath request.body '$.message'}}
c
It works perfect!!! Thank you very much to both of you, you are the best 🙌
🙌🏻 1