Hi all, I am currently running WireMock in a docke...
# help
r
Hi all, I am currently running WireMock in a docker container, I think I don’t have any strange configs in the docker-compose.yml
Copy code
version: "3"
services:
  wiremock:
    image: "wiremock/wiremock:latest"
    container_name: mock-server
    ports:
      - "127.0.0.1:3002:8080"
      - "127.0.0.1:3443:8443"
    volumes:
      - ./extensions:/var/wiremock/extensions
      - ./__files:/home/wiremock/__files
      - ./mappings:/home/wiremock/mappings
    entrypoint: ["/docker-entrypoint.sh", "--global-response-templating", "--disable-gzip", "--verbose"]
    extra_hosts:
      - "host.docker.internal:host-gateway"
In one of my mappings I would like to use the `{{request.body}} (also tried request.host or request.headers.xxx), but it is always empty, am I missing something? This should work right? It does make the call to that
/v1/events/
endpoint but the body is
{ "message": "success", "originalRequestBody": "" }
Copy code
{
  "request": {
    "headers": {
      "x-amz-target": {
        "matches": "AWSEvents.PutEvents"
      }
    }
  },
  "response": {
    "proxyBaseUrl": "<http://host.docker.internal:4566>"
  },
  "serveEventListeners": [
    {
      "name": "webhook",
      "parameters": {
        "method": "POST",
        "url": "<http://host.docker.internal:3000/v1/events/>",
        "headers": {
          "Content-Type": "application/json"
        },
        "body": "{ \"message\": \"success\", \"originalRequestBody\": \"{{request.body}}\" }",
        "delay": {
          "type": "fixed",
          "milliseconds": 1000
        }
      }
    }
  ]
}
hmm reading some older threads in got on the track of using originalRequest.body instead of request.body, that seems to return something
l
Hi, did you get this working with
originalRequest.body
in the end or are you still struggling ?
r
yes it works, now looking for a way to “stringify” json in such a template, but not sure if that exists in Wiremock or if i have to create something myself
l
You mean to escape all the characters that need escaping ?
r
yes so
Copy code
{
  "key1": "value1",
  "key2": "value2"
}
becomes
Copy code
{\"key1\":\"value1\", \"key2\": \"value2\"}
😇
l
Not sure I have seen that done in wiremock but I can have a dig around
r
I search thru the docs but didn’t find it yet, but still WireMock rulez 🤘🏻
r
not yet
l
Not sure how many things you will need to escape but there is a
replace
helper -
{{ replace value "..." "rocks" }}
r
let me try
not yet working, for now I have to park it, but hopefully this afternoon or otherwise this weekend i will deep diver further 😛 , thx for the help Lee
l
No worries. If you can post your request payload I might be able to have a play with it today or over the weekend as well
r
yes, will do so later today, tnx in advance
hi Lee I have to park this to later this week, due to more important items on the backlog 😢
👍 1
l
No worries at all