Stub calls to third party services using WireMock

Viewed 4379

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?

2 Answers

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.

Related