elixir http poisin code example
Example 1: http get elixir
# set HTTPoison, Jason
def deps do
[
{:httpoison, "~> 1.6"},
{:jason, "~> 1.0"},
]
end
# use HTTPoison
HTTPoison.get!("https://api.github.com")
%HTTPoison.Response{status_code: 200,
headers: [{"content-type", "application/json"}],
body: "{...}"}
# use Jason
Jason.encode!(%{"age" => 44})
"{\"age\":44}"
Jason.decode!(~s({"age":44}))
%{"age" => 44}
Example 2: httpoison elixir
def deps do
[
{:httpoison, "~> 1.6"}
]
end
# mix deps.get