Inverse Regular Expression for urlPattern and urlPathPattern

38 views
Skip to first unread message

Deepak Shakya

unread,
Jan 20, 2023, 3:28:56 AM1/20/23
to wiremock-user
Hi,

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
/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.

{
  "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

Thanks,
Deepak Shakya

Deepak Shakya

unread,
Jan 20, 2023, 10:06:57 AM1/20/23
to wiremock-user
Hi,

Porting the response from Slack channel and the way this could work using priority.

Set the Priority of the proxy to 10 or even high value for the proxy configuration, and everything works just. Here is how set it up on my example.

{
  "priority: 100,
   "request": {
    "method": "ANY",
    "urlPattern": "/endpoint/.*"

  },
  "response": {
    "proxyBaseUrl": "http://real-customer-endpoint/api",
    "proxyUrlPrefixToRemove": "/endpoint"
  }
}

Thanks,
Deepak Shakya
Reply all
Reply to author
Forward
0 new messages