Suppose I have to interact with a remote system:
- it can be managed remotely through http
- it replies asynchronously with an http request and expects a custom response body
I would like to hide interaction with it behind some wrapper module, ideally it would allow to do something like this:
I can’t find a non-dirty way to implement this in a self-contained manner. Maybe there is some design pattern I’m missing, I’d be grateful if someone could suggest a better solution.
What I have to do now in my Phoenix app is
- create a
RemoteSystemmodule located in the
- create a route and a controller in the
webdir that has to know the structure of a callback request and would call a
RemoteSystemmodule to build a response body and to process the callback (pass it back to the original caller).
There is also a different service with it’s (own wrapper module implementing the same behaviour) that could be used instead that replies synchronously so when a
RemoteSystem isn’t used (i.e started), it’s controller and routes have to be disabled too.
So the issue is that I can’t completely encapsulate interaction with this async remote system behind some context and it spans throughout the app. Is there a better way to do this?