October 2014
Intermediate to advanced
280 pages
7h 20m
English
We’ll need a JSON library to convert the response into a data structure. Searching hex.pm, I found the Erlang library jsx,[22] so let’s add its dependency to our mix.exs file.
| project/2/issues/mix.exs | |
| | defp deps do |
| | [ |
| | { :httpoison, "~> 0.4" }, |
| | { :jsx, "~> 2.0" } |
| | ] |
| | end |
Run mix deps.get, and you’ll end up with jsx installed.
To convert the body from a string, we call the jsx decode function when we return the message from the GitHub API:
| project/3/issues/lib/issues/github_issues.ex | |
| | def handle_response(%{status_code: 200, body: body}) do |
* | { :ok, :jsx.decode(body) } |
| | end |
| | |
| | def handle_response(%{status_code: ___, body: body}) do |
* | { :error, :jsx.decode(body) } |
| | end |
We also have to deal ...
Read now
Unlock full access