9

I tried to find a way to stub calls to external services via WireMock. WireMock easily mocks any relative URL, but what if we want to intercept a REST call, which was sent from our node to some 3rd party service and return predefined response? Is there any possibility to do that?

Alesto
  • 639
  • 4
  • 13
  • 29

2 Answers2

1

I did a workaround by extracting the host as application configuration.

So if your application sends requests to:

http://thired-party-service.com/someEndPoint

You can extract the host as configuration param:

host=http://thired-party-service.com/

Now when you running in a test context fill the host param with same host as your WireMock server, for example:

host=http://localhost:8080/

Now you can use WireMock stubs as usual.

Ghost
  • 133
  • 1
  • 8
-1

Yes, check out the proxying section in the docs: http://wiremock.org/docs/proxying

Tom
  • 3,471
  • 21
  • 14
  • Is there a working sample for the above case? Docs doesn't look that helpful to me – Andrea Di Lisio Dec 10 '19 at 16:08
  • 4
    It's not possible, proxying section is all about intercepting call to local wiremock and "forward" to a defined remote service (possibly on another host). I guess the question is about the other way around....so client calling http://remoteHost.some/service and the answer to be intercepted by wiremock running inside the same VM or anyway on the same host as the client itself – Raffaele Dec 11 '19 at 13:56
  • I agree... this is also my understanding as of now – Andrea Di Lisio Dec 11 '19 at 13:59