Sample: GET /person/42
will return content of file /home/wiremock/__files/person-42.json
{
"request": {
"method": "GET",
"urlPattern": "/person/\\d+"
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": "{{#assign 'filename'}}person-{{{request.pathSegments.1}}}.json{{/assign}} {{file-content filename}}"
}
}
{
"response": {
"body": "{{#assign 'filename'}}person-{{{request.pathSegments.1}}}.json{{/assign}} {{#if (file-exists filename)}} [...] {{/if}}"
}
}
Build "get multiple" response dynamically from splitted unitary files:
[
{{#each (parseJson request.body) as |id|}}
{{#assign 'filename'}}subFolder/{{{id}}}.json{{/assign}}
{{#if (file-exists filename)}}
{{file-content filename}}
{{/if}}
{{#if @last}}{{else}},{{/if}}
{{/each}}
]
The extension is auto-loaded: just add JAR to classpath.
wget https://.../wiremock-files-extension.jar
Docker compose:
services:
mocks:
image: wiremock/wiremock:3x
volumes:
- ./wiremock-files-extension.jar:/var/wiremock/extensions/wiremock-files-extension.jar