https://linen.dev logo
#help
Title
# help
c

Carlos Villar

09/12/2023, 2:53 PM
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

Tom

09/12/2023, 3:01 PM
Hi @Carlos Villar, try adding
--local-response-templating
to your startup params
c

Carlos Villar

09/12/2023, 3:13 PM
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

Aaron

09/12/2023, 3:27 PM
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

Carlos Villar

09/12/2023, 3:36 PM
It works perfect!!! Thank you very much to both of you, you are the best 🙌
🙌🏻 1