https://linen.dev logo
#help
Title
# help
o

Oswald Quek

01/31/2024, 10:47 AM
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

Tom

01/31/2024, 11:06 AM
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

Oswald Quek

01/31/2024, 11:40 AM
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

Tom

01/31/2024, 2:51 PM
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

Oswald Quek

02/01/2024, 9:54 AM
Amazing, that worked. Thanks.
2 Views