Current section
Files
Jump to
Current section
Files
lib/tw/http/client/hackney.ex
defmodule Tw.HTTP.Client.Hackney do
@moduledoc """
Hackney-based HTTP client adapter.
"""
@behaviour Tw.HTTP.Client
@impl true
def request(method, url, headers, body, opts) do
with {:ok, status, headers, body_ref} <- :hackney.request(method, url, headers, body, opts),
{:ok, body} <- :hackney.body(body_ref) do
{:ok, %{status: status, headers: headers, body: body}}
else
{:error, reason} ->
{:error, RuntimeError.exception(inspect(reason))}
end
end
end