Packages
httpoison
0.7.0
3.0.0
2.3.0
2.2.3
2.2.2
2.2.1
2.2.0
2.1.0
2.0.0
1.8.2
1.8.1
1.8.0
1.7.0
1.6.2
1.6.1
1.6.0
1.5.1
1.5.0
1.4.0
1.3.1
1.3.0
1.2.0
1.1.1
1.1.0
1.0.0
0.13.0
0.12.0
0.11.2
0.11.1
0.11.0
0.10.0
0.9.2
0.9.1
0.9.0
0.8.3
0.8.2
0.8.1
0.8.0
0.7.5
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.2
0.6.1
0.6.0
0.5.0
0.4.3
0.4.2
0.4.1
0.4.0
0.3.2
0.3.1
0.3.0
0.2.0
Yet Another HTTP client for Elixir powered by hackney
Current section
Files
Jump to
Current section
Files
lib/httpoison.ex
defmodule HTTPoison do
@moduledoc """
The HTTP client for Elixir.
The `HTTPoison` module can be used to issue HTTP requests and parse HTTP responses to arbitrary urls.
iex> HTTPoison.get!("https://api.github.com")
%HTTPoison.Response{status_code: 200,
headers: [{"content-type", "application/json"}],
body: "{...}"}
It's very common to use HTTPoison in order to wrap APIs, which is when the
`HTTPoison.Base` module shines. Visit the documentation for `HTTPoison.Base`
for more information.
Under the hood, the `HTTPoison` module just uses `HTTPoison.Base` (as
described in the documentation for `HTTPoison.Base`) without overriding any
default function.
"""
defmodule Response do
defstruct status_code: nil, body: nil, headers: []
@type t :: %Response{status_code: integer, body: binary, headers: list}
end
defmodule AsyncResponse do
defstruct id: nil
@type t :: %AsyncResponse{id: reference}
end
defmodule AsyncStatus do
defstruct id: nil, code: nil
@type t :: %AsyncStatus{id: reference, code: integer}
end
defmodule AsyncHeaders do
defstruct id: nil, headers: []
@type t :: %AsyncHeaders{id: reference, headers: list}
end
defmodule AsyncChunk do
defstruct id: nil, chunk: nil
@type t :: %AsyncChunk{id: reference, chunk: binary}
end
defmodule AsyncEnd do
defstruct id: nil
@type t :: %AsyncEnd{id: reference}
end
defmodule Error do
defexception reason: nil, id: nil
@type t :: %Error{id: reference, reason: any}
def message(%Error{reason: reason, id: nil}), do: inspect(reason)
def message(%Error{reason: reason, id: id}), do: "[Reference: #{id}] - #{inspect reason}"
end
use HTTPoison.Base
end