Transformation: Convert Response

We’ll need a JSON library to convert the response into a data structure. Searching, I found the poison library (no relation to HTTPoison), so let’s add its dependency to our mix.exs file.[23]

  defp​ deps ​do
  { ​:httpoison​, ​"​​~> 1.0.0"​ },
  { ​:poison​, ​"​​~> 3.1"​ },

Run mix deps.get, and you’ll end up with poison installed.

To convert the body from a string, we call the Poison.Parser.parse! function when we return the message from the GitHub API:

  def​ handle_response({ _, %{​status_code:​ status_code, ​body:​ body}}) ​do
  status_code |> check_for_error(),
  body ...

Get Programming Elixir 1.6 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.