Current section
Files
Jump to
Current section
Files
lib/discovergy/http_client/finch.ex
defmodule Discovergy.HTTPClient.Finch do
@moduledoc """
The built-in HTTP client, based on [finch](https://github.com/sneako/finch).
It client implements the `Discovergy.HTTPClient` behaviour.
See `Discovergy` for the available configuration options and `Discovergy.HTTPClient` if you wish
to use another HTTP client.
"""
@behaviour Discovergy.HTTPClient
@finch_pool_name Discovergy.Finch
@impl true
def child_spec(pool_opts) do
Finch.child_spec(name: @finch_pool_name, pools: %{default: pool_opts})
end
@impl true
def request(method, url, headers, body, opts) do
req = Finch.build(method, url, headers, body)
case Finch.request(req, @finch_pool_name, opts) do
{:ok, %{status: status, headers: headers, body: body}} ->
{:ok, status, headers, body}
{:error, reason} ->
{:error, reason}
end
end
end