May 2018
Intermediate to advanced
412 pages
9h 3m
English
We’ll need a JSON library to convert the response into a data structure. Searching hex.pm, 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" }, |
| | ] |
| | end |
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 |> Poison.Parser.parse!() |
| | } |
| | end |
| | |
| |
Read now
Unlock full access