Am I using request.requestLine.path.[<n>] response template correctly?

815 views
Skip to first unread message

Bassam Khouri

unread,
Aug 9, 2018, 10:29:25 AM8/9/18
to wiremock-user
Hi,

First of all, I am new to Wiremock and I don't know if I encountered a defect or a usability issue.

I started wiremock version v2.18.0 (with the options --verbose --global-response-templating --local-response-templating) on local machine on port 8088 and added the following mapping in wiremock


{
"request": {
"urlPattern": "/template/.*"
},
"response" : {
"status" : 200,
"bodyFileName": "body-templated.json",
"headers" : {
"Cache-Control" : "no-cache, must-revalidate, no-store",
"Connection" : "keep-alive",
"Content-Type" : "application/json",
"Date": "{{now timezone='GMT' format='EEE, dd MMM yyyy HH:mm:ss z'}}",
"Server" : "WildFly/8",
"Transfer-Encoding" : "chunked",
"X-Powered-By" : "Undertow/1"
},
"transformers": ["response-template"]
}
}


The body-templated.json file contents are

{
"request.requestLine.baseUrl": "{{request.requestLine.baseUrl}}",
"request.url": "{{request.url}}",
"request.requestLine.path": "{{request.requestLine.path}}",
"request.requestLine.path.0": "{{request.requestLine.path.0}}",
"request.requestLine.path.1": "{{request.requestLine.path.1}}",
"request.requestLine.path.2": "{{request.requestLine.path.2}}",
"request.requestLine.path.[0]": "{{request.requestLine.path.[0]}}",
"request.requestLine.path.[1]": "{{request.requestLine.path.[1]}}",
"request.requestLine.path.[2]": "{{request.requestLine.path.[2]}}",
"request.requestLine.query": "{{request.requestLine.query}}",
"request.requestLine.query.token": "{{request.requestLine.query.token}}",
"request.requestLine.query.relationship": "{{request.requestLine.query.relationship}}",
"headers": {
"request.headers.hops": "{{request.headers.hops}}"
}
}


{

  "request.requestLine.baseUrl": "http://localhost:8088",

  "request.url": "/template/foo?relationship&#x3D;foodfg",

  "request.requestLine.path": "/template/foo?relationship&#x3D;foodfg",

  "request.requestLine.path.0": "",

  "request.requestLine.path.1": "",

  "request.requestLine.path.2": "",

  "request.requestLine.path.[0]": "",

  "request.requestLine.path.[1]": "",

  "request.requestLine.path.[2]": "",

  "request.requestLine.query": "{relationship&#x3D;foodfg}",

  "request.requestLine.query.token": "",

  "request.requestLine.query.relationship": "foodfg",

  "headers": {

    "request.headers.hops": ""

  }

}


From the documentation found here http://wiremock.org/docs/response-templating/ (I also compared the documentation of v2.18.0 here), states
 request.requestLine.path.[<n>]- URL path segment (zero indexed) e.g. request.path.[2]

Based on this, I was expecting request.requestLine.path.[0] to return template and to request.requestLine.path.[1] return foo.  Am I using the request.requestLine.path.[<n>] properly?  If so, is there a known issue against it (I couldn't find anything in the wiremock github issue list related to this)

Cheers,

Bassam

Bassam Khouri

unread,
Aug 9, 2018, 10:47:32 AM8/9/18
to wiremock-user
Looks like the documentation is incorrect as using the following body worked.

The template {{request.path.<n>}} or {{request.path.[<n>]}} seem to be the correct way to get part of the path.

{
"request.requestLine.baseUrl": "{{request.requestLine.baseUrl}}",
"request.url": "{{request.url}}",
  "request.path": "{{request.path}}",
"request.path.0": "{{request.path.0}}",
"request.path.1": "{{request.path.1}}",
"request.path.2": "{{request.path.2}}",
"request.path.[0]": "{{request.path.[0]}}",
"request.path.[1]": "{{request.path.[1]}}",
"request.path.[2]": "{{request.path.[2]}}",

Tom Akehurst

unread,
Aug 9, 2018, 10:47:34 AM8/9/18
to wiremock-user
Ah, seems you've spotted a bug in the docs!

You can either do request.path.[5] or request.requestLine.pathSegments.[5]

Bassam Khouri

unread,
Aug 9, 2018, 1:02:54 PM8/9/18
to wiremock-user
Thanks for confirming.  I created https://github.com/tomakehurst/wiremock/issues/975 to get the documentation updated.
Reply all
Reply to author
Forward
0 new messages