proxywiremock

Wiremock proxy unmatched requests


I am investigating a possibility to proxy all the request that do not have mappings in Wiremock. I found a mechanism to proxy requests creating a mapping for that. But I want to have an ability to say: "Wiremock, if there is no mappings for that request, please proxy it to www.my-address.com" please.

Have anyone done this before? Thanks!

I found a mechanism to proxy requests creating a mapping for that. But I want to have an ability to say: "Wiremock, if there is no mappings for that request, please proxy it to www.my-address.com" please.


Solution

  • You can use the priority field to set your "catch-all" proxy to a lower priority than all other mappings.

    In the example below, there are two mappings. The first is matched on the url /foo. The second matches all other URLs. The first is checked before the second, because of the higher priority (lower number == higher priority). If a match is found, then WireMock stops checking. So, calls to /foo are checked and matched before they get the opportunity to be caught by the catch-all.

    {
      "mappings": [
        {
          "priority": 1,
          "request": {
            "url": "/foo"
          },
          "response": {
            "status": 200
          }
        },
        {
          "priority": 5,
          "request": {
            "urlPathPattern": ".*"
          },
          "response": {
            "proxyBaseUrl": "https://www.my-other-site.com"
          }
        }
      ]
    }