I am in the process of learning to build a library for the third party api.
I am not so sure how to start it. If anybody has any recommended steps please put them here.
I am thinking of using HTTPoison, and Poison for HTTP client and for parsing Json respectively.
The current issue that I am finding here is How would one write configs for development and for testing and for the moment is included into another app.
If anybody has any past experience on this. I would be really appreciated for recommendations.
Thank you in advance.
You’re on a good path. Have a look at ex_aws - it’s doing basically the same thing, i.e. wraps HTTP API.
The tough part might be to decide which config options go into config and which ones you want to pass around. One thing that makes many libraries useless for me is when I build a multi-tenant app and the library wants me to put the API key into the config, whereas I need to make an API call with different API keys.
Very often the first thing I do, after creating the project with
mix new, is to write a
README.md and explain what the library is, common usage and configuration. I find it to be a good exercise before getting on with the actual implementation.
Looks like “Readme Driven Development” is already a term:
Yeah, this is one thing that bugs me about ueberauth, too much config file stuff…
In regards to configuration for your library, I really like what @michalmuskala lays out in this article: http://michal.muskala.eu/2017/07/30/configuring-elixir-libraries.html
@stefanchrobot Thank you for recommending
ex_aws I will definitely look there as my starting point. I also have faced similar problems in multi tenant app. Will have to think wisely about the configuration parts.
@svilen Thank you for recommending about “Readme Driven Development”. Will look there also. Cause I will opensource this library. I think it is good to do the README from day one
@axelson Thank you for recommending, the article about the configuration. Will be looking there also.
Another good resource is the Elixir Library Guidelines, specifically the section on avoiding application configuration.
I wrote ex_force for Salesforce REST API and use it in a project - here are my tips
- Avoid application config or global default config if possible
- Provide a function which takes all configuration, so that your “library” only takes about HTTP interaction, not how to pass configuration
- Let other component take care of actual configuration and authentication (e.g. GenServer)