I’m using the http4k testing hyperpyramid talk/exa...
# http4k
a
I’m using the http4k testing hyperpyramid talk/example as inspiration for my current applications’s architecture. I really like this approach, especially how it allows for easy testing and separation of concerns. I’m also using TracerBullet to generate puml files from my tests, which are great. When I communicate with remote services, I get that these are essentially HttpHandlers that I have to create to have this tracing automatically. But how can I best approach this if I use an SDK instead of an API? I’ve been looking into several examples where they communicate with remote services, but they all seem to use an actual API instead of an SDK
s
If by SDK you mean a client library to talk to remote services, we have a well established pattern (connect) that we've been using to successfully replace SDKs (e.g. AWS) with something lighter and with the same testing properties as you get from any HttpHandler. Now, if you're dealing with SDKs that perform other kinds of tasks (e.g. generate PDFs), you can still follow a similar (hexagonal) approach by introducing and interface and having fake + real code performing the operations you're interested in.
j
To add to what Ivan was saying, sometimes you can replace an http client in an sdk with a different implementation. You can write an adapter between whatever that client interface is and an httphandler. This can reduce the amount of work. It's not always applicable, but sometimes...
💯 3
a
Yes to what James said. I've even managed to get an auto-generated soap client to go through an httphandler, which I can subsequently fake for testing.
d
it's tricky if you can't inject the HTTP services. You can use a custom tracer (like the db tracer that we used in the talk) to make it work though
a
It’s indeed a client library to talk to remote services, where they handle the HTTP connection themselves. This means I cannot use the default HttpTracer. I did indeed already see the connect pattern, which I really like. I’ve looked at the source code of several connect modules, but it seems they all have a HttpHandler eventually. I couldn’t find any examples where there wasn’t an HttpHandler, sadly enough. I was hoping I missed an example somewhere 😅 But I’ll try to figure something out with a custom tracer then. Thanks for the pointers!
d
Yes - all of the modules are based around a handler, but there is no reason why you couldn't adapt the pattern to be based on something else, as long as it had the same request/response semantics. The pattern doesn't care - just the http4k-connect implementation 🙂
👍 1