Packages
aws
0.13.3
1.0.14
1.0.13
1.0.12
1.0.11
1.0.10
1.0.9
1.0.8
1.0.7
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0
0.14.1
0.14.0
0.13.3
0.13.2
0.13.1
0.13.0
0.12.0
0.11.0
0.10.1
0.10.0
0.9.2
0.9.1
0.9.0
0.8.0
0.7.0
0.6.0
0.5.0
0.4.0
0.3.0
0.2.0
0.1.0
0.0.12
0.0.11
0.0.10
0.0.9
0.0.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1
AWS clients for Elixir
Current section
Files
Jump to
Current section
Files
lib/aws/http_client/finch.ex
defmodule AWS.HTTPClient.Finch do
@moduledoc """
Finch-based HTTP client for AWS.
In order to use `Finch` API client, you must start `Finch` and provide a `:name`. In
your supervision tree:
children = [
{Finch, name: AWS.Finch}
]
Then build AWS client with the provided `:finch_name`:
client = %AWS.Client{http_client: {AWS.HTTPClient.Finch, [finch_name: AWS.Finch]}}
AWS.SNS.publish(client, "My message")
In case you omit `:finch_name`, it defaults to `AWS.Finch`.
"""
require Logger
@behaviour AWS.HTTPClient
@impl AWS.HTTPClient
def request(method, url, body, headers, options) do
ensure_finch_running!()
finch_name = Keyword.get(options, :finch_name, AWS.Finch)
url = IO.iodata_to_binary(url)
request = Finch.build(method, url, headers, body)
case Finch.request(request, finch_name, options) do
{:ok, response} ->
{:ok, %{status_code: response.status, headers: response.headers, body: response.body}}
{:error, _reason} = error ->
error
end
end
defp ensure_finch_running! do
unless Code.ensure_loaded?(Finch) do
Logger.error("""
Could not find finch dependency.
Please add :finch to your dependencies:
{:finch, "~> 0.13.0"}
Or provide your own #{AWS.HTTPClient} implementation:
%AWS.Client{http_client: {MyCustomHTTPClient, []}}
""")
raise "missing finch dependency"
end
{:ok, _apps} = Application.ensure_all_started(:finch)
end
end