ardanlabs / service

Starter-kit for writing services in Go using Kubernetes.

Home Page:https://www.ardanlabs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: What is best practices for using an external API?

David-Kalashir opened this issue · comments

I have an external API that I want to use. How should I incorporate it into the core of my project? Where should its converters be placed? Additionally, if I want to cache the data from this API, what is the best approach? Given that the API supplier may change in the future, would it be better to create an abstraction layer and use an interface to interact with it? I could then create a sub-folder for this layer, similar to how the stores were organized, and use the interface within the core.

We use external API's all the time. You would pass that into any Core business package that needs it. I would probably build a convience package under foundation for these external APIs or just bring them in directly.

Don't add the interface until you need it. Discover interfaces, don't Design with interfaces. You said "may change", so don't code for maybe, code for what you need now.