Handwrite - Unofficial API wrapper for Handwrite.io

Oh, I agree with you in that global config for a library must be avoided.

I should have been more clear on this part :man_facepalming: I wanted to give hints to move away from using System.get_env/1 first…

For starter - and this kind of library, this is very likely to have one instance - which is “acceptable” (although I don’t prefer) to have (global) application config. That’s why I refer to the library guides lines, which has a section for Avoid application configuration :slight_smile:


@timpile for the configuration - it’s better to have a library to provide building blocks and let library users load config as needed.

For example:

# in config
config :my_app, :handwrite, url: "https://example.com", api_key: "..."

# in your helper module

defmodule MyApp.Handwrite do
  def client do
    opts = Application.get_env(:my_app, :handwrite)
   Handwrite.client(Keyword.fetch!(opts, :url), Keyword.fetch!(opts, :api_key)
  end
end

# then you use it like this

MyApp.Handwrite.client()
|> Handwrite.create_whatever(my_opts)

By doing this, your library does not care how to store and retrieve the configuration at all - and that is in the library user code.


I did make a mistake when I wrote the first library - I had default config value and make authentication happens when not passed to make it easy to use.. but I found it’s not good. See my commit to change from httpoison to tesla with 1) dropping default config and 2) making all functions to take a tesla struct, which holds the all information such as url and auth token - see Replace HTTPoison with Tesla · chulkilee/ex_force@8d32d9a · GitHub