I have a question about how best to handle fetching data from a third-party API within the architecture of my phoenix app. Essentially, I have a controller that receives the client’s IP address as a parameter. I then need to fetch the geolocation associated with that IP address from an external API and store both in the database (i.e., ip and geolocation).
Right now my approach is to use a plug, and then return the result in the connection struct.
But I could also fetch the data by creating a function directly in the model, and then call it during the changeset operations.
Or perhaps there’s another alternative such as making it an OTP app.
Looking for some guidance on the best approach here, or at least the tradeoffs of one vs the other.
Although my scenario is specific, this is probably a common design question that people encounter.