title: Wiremock - Grab a string from the URL, modify it and return it as part of the body
body: <p>I'm working on some load test scenarios at work and I'm having some issues figuring out how to do this with Wiremock. </p>
  
  <p>It's basically this. I have a piece of code that makes a <code>GET</code> to an endpoint that looks something like <code>/api/1/external/client/1234%12LT</code> and I want to grab the last part, strip everything after the <code>%</code> (included) and only return the numbers before it as part of a very simple JSON <code>{"id": "1234"}</code>. </p>
  
  <p>I've been reading about the <code>Response Templating</code> and enabled it on my standalone instance by passing the flag <code>--global-response-templating</code> on the command line. I <em>think</em> it works because if I set it to return a random value using something like <code>{{randomValue length=10 type='NUMERIC'}}</code> it actually returns a random number. </p>
  
  <p>I think I should be using a combination of <code>request.requestLine.pathSegments.[4]</code> to get the last segment of the URL then use the regular expression extractor <code>{{regexExtract request.body '[A-Z]+'}}"</code> (not the actual code, example is taken from documentation) to get the first numerical part but haven't managed to make it work yet. </p>
  
  <p>My mocking code looks something like this: </p>
  
  <pre><code>{
    "request": {
      "urlPattern": "/api/1/example/endpoint/.*",
      "method": "GET"
    },
    "response": {
      "status": "200",
      "headers": {
        "Content-Type": "application/json; charset=utf-8"
      },
      "jsonBody": {
        "id": "{{request.requestLine.pathSegments.[4]}}"
      }
    }
  }
  </code></pre>
  
  <p>Could anyone point me to where I'm screwing up?. </p>
  
  <p>And another question, how do you debug this usually? I've gone over the docs and not sure how to print info to the logs to see if the substitution I'm trying to do is actually working or if what is reaching the endpoint is what I'm assuming should be getting. </p>
  
  <p>Thanks.</p>