How to set wiremock to mock specified url

1,180 views
Skip to first unread message

Shell Scott

unread,
Apr 3, 2018, 4:30:49 PM4/3/18
to wiremock-user

I have microservice based app, and I need to mock one of the service. So when Im requesting one microservice http://service1/src it triggers another one by link lets say http://service2/src I cannot change this link to the mocked one but I want to start wiremock somehow and fake this link, so when I will send request to http://service1/src it will trigger http://service2/src but mocked one

Im able to setup wiremock but I cannot get it directly by link http://service2/src I need to add http://localhost:8080/http://service2/src

Tom Akehurst

unread,
Apr 4, 2018, 9:07:16 AM4/4/18
to wiremock-user
OK, so I understand correctly - you're testing a microservice that calls an external API, but you can't change the base URL or host in the configuration to point to WireMock instead of the real API?

If this is the case, you might want to look at using WireMock as a forward proxy. You'd need to set the --enable-browser-proxying flag when starting WireMock and configure the microservice to use WireMock's host/port as its proxy server.

Shell Scott

unread,
Apr 4, 2018, 9:36:57 AM4/4/18
to wiremock-user
its all the same...I wont be able to get http://service2/src, with proxy I should put '/' at the beggining
what I need, is for example www.google.com, I need to mock it with the exact same url.


среда, 4 апреля 2018 г., 15:07:16 UTC+2 пользователь Tom Akehurst написал:

Tom Akehurst

unread,
Apr 4, 2018, 9:40:50 AM4/4/18
to wiremock-user
I'm not sure I understand the problem you're describing in that case.

Can you elaborate it in a bit more detail?

Shell Scott

unread,
Apr 4, 2018, 9:44:57 AM4/4/18
to wiremock-user
Sure, the question is: can I using wiremock  to mock next situation
Im opening postman and make get request

www.google.com

and to get response as not google website, but my mock?

среда, 4 апреля 2018 г., 15:40:50 UTC+2 пользователь Tom Akehurst написал:

Tom Akehurst

unread,
Apr 4, 2018, 9:48:22 AM4/4/18
to wiremock-user
If you configured Postman's proxy to be your WireMock server then you could do that. I'm not sure why this isn't an option for you.

Failing that I suppose you could hack your hosts file, or put your microservice under test into a DNS sandbox of some kind (so that a DNS lookup for www.google.com would return the IP of your WireMock host).

cchike4

unread,
Apr 12, 2018, 7:12:49 PM4/12/18
to wiremock-user
I think I have the same question. My application calls various external APIs. Whenever my application calls http://service1.com/service1 I want to return someMockData and when it calls http://service2.com/service2 I want to return otherMockData, etc.. We are trying to configure mocks without going into the code and switching the base URLs of the API calls to be http://localhost:8080. Is this the right framework to choose for implementing something like that?
Reply all
Reply to author
Forward
0 new messages