As part of my Elixir learning path, I decided that I am ready to extend my Elixir portfolio with a paid gig on Upwork. In my RSS reader Newsblur, I am using RSS feed to monitor for Elixir jobs. There was a job to create an open-source Elixir Library for KeyCDN API. I did not get the job, but I found it an excellent opportunity to create my first open-source Elixir contribution.
Tesla Hex Package
I learned from Alexandru about a trendy HTTP Elixir client, Tesla.
ExKeyCDN Hex Package
It took me 15 hours to do this library. I decided to create a Struct for each Data Type used in KeyCDN API. With struct abstractions, we move from HTTP to the KeyCDN business domain. Here are examples of how you can use the ExKeyCDN library.
How To Create Hex Library
First, create a new mix project with:
mix new exkeycdn
you need to add to
mix.exs project() function,
The next step is to create
mix hex.user register
Now do your standard Elixir development and create modules and tests for your library. KeyCDN API does not have a sandbox environment for testing, so you can only use your production key API. Not so good for your Integration tests because you could easily deplete your hourly API limit.
You will need to use some kind of mocking. By implementing ExKeyCDN using Elixir behaviors, you can use Mox mocking library. Why Mox? Because you do not give up concurrency execution in your tests.
test_helpers.exs you need to add these two lines:
Do not forget to document your library using
@doc attributes that are read by
mix docs Creates awesome Elixir library.
Publish To Hex
With the following two commands starts your Elixir glory:
Your library is publically available on Hex.pm!