Mocking HTTP requests
Earlier in this chapter, we talked about how the injection is not the answer to all problems and, in some cases, passing in configuration is far more efficient and a whole lot less code. A frequently occurring example of this occurs when we deal with external services, particularly HTTP services such as the upstream currency conversion service in our sample service.
It is possible to mock an HTTP request to the external service and use the mock to thoroughly test calls to an external service, but it's just not necessary. Let's look at a side-by-side comparison of mocking versus config by using code from our sample service.
The following is the code from our sample service, which calls to the external currency conversion ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access