Hi team: Is there a way to have the wiremock Reque...
# help
b
Hi team: Is there a way to have the wiremock Request Matching be able to reference environment variables? I saw that there was a way to do this on response templating (https://wiremock.org/docs/response-templating/#system-property-helper) but not sure how to do the same in my request matching
b
I don’t think the builtin request marchers support environment variables, but you can use them in a custom matcher: https://wiremock.org/docs/extensibility/custom-matching/
b
In order to do this, do you have to write java/sdk code for this? or can it all be done in the json?
b
You have to write some Java (or at least that’s how I’ve always done it). I don’t think there’s a way to define custom matchers in JSON.
b
Okay - so far I've only been using the json files, do you have any example repos/tips for starting out the java parts? its my first time using java with wiremock
b
Here’s one from my open source WireMock workshop: https://github.com/basdijkstra/wiremock-workshop/blob/main/src/test/java/answers/extensions/RejectedHttpVerbsMatcher.java - this shows how to create a matcher that rejects certain HTTP verbs
You could either pass in the env variables as parameters to the matcher or just reference them in the implantation of the
match()
method, whatever you prefer
Although from your context I think you’ll go for the second option. By the way, to add the extension to your WireMock instance you don’t need to start WM in Java, you can register custom extensions through the command line using the
extensions
flag
b
thank you!
🙌 1