Calling http service during macro expansion

I am trying to make a one time verification call to a webservice (document database api) while expanding a macro. The use case is to define a ‘collection’ for a document module, and this collection would have to be instantiated once when it doesn’t exist. The alternative would be to do this on each subsequent function call, which would be an unnecessary performance hit.

However, I have come to understand the application isn’t fully started yet when the macro is being expanded, so the call inside my defmacro stumbles on a

    ** (EXIT) no process

error from httpoison/hackney.

So my question is: what would be the preferred way of doing this? I am guessing I should be using module attributes, but I am not fully up to speed on them. Or is there another way of controlling this?

Not 100% sure if it would work but perhaps explicitly starting it via HTTPoison.start before attempting your request may do the trick? Not sure what implications that has, if any.

Thanks, that works, but I ended up solving it with the more precise Application.ensure_all_started(:httpoison)