Hi, I would like to use parameters from a `request...
# help
r
Hi, I would like to use parameters from a
request
-
"urlPathTemplate": "/organizations/{organization}/members/{member}"
inside a
serveEventListeners
-
"url": "<https://my.organization.net/webhook-processor/organizations/{{originalRequest.path.organization}}/members/{{originalRequest.path.member}}/activated>"
. It seems that this is only possible inside a
response
definition. Any advice e.g. available extensions to help me?
t
This is a timely reminder we need to fix this in the next release now that we’ve fixed the prerequisite bits in the template engine. For now you need to use numbered path indexes e.g.
{{originalRequest.path.3}}
r
Thank you for your reply. I'm using e.g.
{{originalRequest.pathSegments.3}}
now and it works. As a side quest: It would be really cool if the wiremock-jwt-extension would be able to encode the parameters inside the jwt as well, e.g.
"Authorization": "Bearer {{{jwt maxAge='5 seconds' sub='{{originalRequest.pathSegments.3}}' }}}"
l
Hi @Rainer Scholz What version of WireMock are you using ?
r
I use the container image holomekc/wiremock-gui:3.6.26 which turned out to be using Wiremock 3.5.4.
l
I would need to check but I am pretty sure the latest official release of Wiremock have this functionality available https://github.com/wiremock/wiremock/releases
Just ran a quick test and this all seems to be working fine in the latest WireMock release. I tested in
3.8.0
but I think this should work in the previous release as well -
3.7.0
Copy code
{
  "request": {
    "method": "POST",
    "urlPathTemplate": "/transfer/{name}"
  },
  "response": {
    "status": 200,
    "jsonBody": {
      "message": "transfer succeeded!"
    },
    "headers": {
      "Content-Type": "application/json"
    }
  },
  "serveEventListeners": [
    {
      "name": "webhook",
      "parameters": {
        "method": "POST",
        "url": "<https://webhook.site/2865e463-1f98-4899-8837-90b89364a5dc/{{originalRequest.path.name}}>",
        "headers": {
          "Content-Type": "application/json",
          "Accept": "application/json"
        },
        "body": "{\"oldState\": {}, \"newState\": {}}"
      }
    }
  ]
}
A webhook request was made to
<https://webhook.site/2865e463-1f98-4899-8837-90b89364a5dc/lee>
when I posted a request to
<http://localhost:8080/transfer/lee>
🙌 1
r
This sounds excellent, I'll give it a try.
@Lee Turner Holomekc (https://github.com/holomekc) was kind enough to provide a Wiremock GUI (3.7.1) release containing Wiremock 3.8.0. I was able to confirm that the template
{{originalRequest.path.name}}
is working like you described. I'm also able to confirm that using templates inside wiremock-jwt-extension (e.g.
"Authorization": "Bearer {{{jwt maxAge='5 seconds' sub='{{originalRequest.path.name}}' }}}"
) are not working, but that's probably another topic.
l
Excellent, I am glad that it is working.
I had a look at the jwt issue you mentioned. Give this a try and see if it works for you -
Authorization": "Bearer {{{jwt maxAge='5 seconds' sub=(trim originalRequest.path.name) }}}
🎉 1
r
@Lee Turner Awesome, works like a charm. Thank you and have a nice weekend.
🙌 1