Has anybody tried the inverse regular expression w...
# wiremock-java
d
Has anybody tried the inverse regular expression with urlPattern and urlPathPattern? I wanted to configure those in the proxies so that all requests are routed to the proxy except for the ones that I configure as the mock. For example, I have two mocks at following endpoints
Copy code
/endpoint/customers/abc123
/endpoint/customers/abc456
For requests that come for the above paths (
/endpoint/customers/abc\d+
), I want the mocks to be used. For anything else, it can routed to the proxy. Here is how I am trying to configure the proxy.
Copy code
{
  "request": {
    "method": "ANY",
    "urlPattern": "/endpoint/customers/(?!abc\\d+)"
  },
  "response": {
    "proxyBaseUrl": "<http://real-customer-endpoint/api>",
    "proxyUrlPrefixToRemove": "/endpoint"
  }
}
But this doesn't seem to work. Am I missing something or this is not possible? Also, what are your thoughts on having the inverse filters likes urlPatternNotMatching and urlPathPatternNotMatching as I suggested them here - https://github.com/wiremock/wiremock/issues/2068
r
You could just use priorities - create your proxy with priority 10, then any other stub will default to priority 5 so will be chosen ahead of the proxy
Then you don't ned to worry about excluding, you can use a general regex pattern for the proxy and a more specific one for the real stubs.
We often develop in WireMock Cloud using an
ANY /.*
proxy at priority 10 to the real API and then adding new functionality in specific stubs.
d
Let me try this out and I will ask if I have any following question. Thank you so much.
Priority works perfectly.
👍 1
Btw, any thoughts on the ticket that I created - https://github.com/wiremock/wiremock/issues/2068
r
I think this effectively already exists... just let me have a look
Hmm - there is a
notMatching
regex inverter but there's no way to apply it to a url at the moment, only query params, headers & the body. Seems a reasonable ask; will look into it.