Search code examples
wiremock

WireMock: Temp disable stub response


I use WireMock to stub responses from remote server. In folder wiremock/mappings I have many files that set rules for stub. Here example:

{

  "request": {
    "method": "GET",
    "url": "/merchant"
  },
  "response": {
    "headers": {
      "Content-Type": "application/json"
    },
    "status": 200,
    "fixedDelayMilliseconds": 3000,
    "bodyFileName": "stub_response.json"
  }
}

As you can see, when I get request /merchant then return stubbed response from file stub_response.json. Nice. It's work fine.

But suppose I need temporary to disable this response. Is it possible to turn off stub response and return real response from remote server?

I need flag like this : "disable" : true

Is it possible in WireMock?


Solution

  • You can disable a rule by using the WireMock admin interface. If you invoke a DELETE command against http://.../__admin/mappings/<guid>, then the mapping will be deleted.

    You can get a list of all the guids by performing a GET command against http://.../__admin/

    If you want to replace a mapping with a real response instead of a stubbed response, you can add a second mapping that has a lower priority than the stubbed response and that proxies through to the real address. Normally, your stubbed response ill be used, but when you then delete the stubbed response, Wiremock will proxy through to the real address as it will then become the highest priority mapping.

    To add a proxy, add the following into the response mapping

    "proxyBaseUrl" : "http://otherhost.com",

    To set the priority of mappings, add the following into your mapping JSON.

    "priority": 1,