Is there a way to <enable dynamic response templat...
# help
o
Is there a way to enable dynamic response templating via the Java API and not the UI? I currently have
Copy code
WireMock wm = WireMock.create()
                .scheme("https")
                .host("...")
                .port(443) //etc

wm.register(post(urlMatching("/a-url"))
                .willReturn(aResponse()
                        .withStatus(200)
                        .withBody(readFile("aFile.html"))
                        .withHeader("Content-Type", "text/html")));
t
Local response templating (where it must be enabled per stub) is on by default in the latest version. So stubs created with
.withTransformers("response-template")
will have it enabled.
o
Thanks. I replaced
.withBody(readFile("aFile.html"))
with
.withTransformers(readFile("aFile.html"))
and this is what I got in the UI - there's nothing in the body and dynamic response templating isn't enabled. I am on the wiremock latest version 3.3.1 too. Might it be because I'm on the free plan?
t
You need to literally use
.withTransformers("response-template")
on your stubs, and if you want the response template in a separate file use
.withBodyFile("path/to/your/file")
o
Amazing, that worked. Thanks.