Adapter for finch.
Remember to add {:finch, "~> 0.14.0"} to dependencies. Also, you need to
recompile tesla after adding the :finch dependency:
mix deps.clean tesla
mix compile
Examples
In order to use Finch, you must start it and provide a :name. For example,
in your supervision tree:
children = [
{Finch, name: MyFinch}
]You must provide the same name to this adapter:
# set globally in config/config.exs
config :tesla, :adapter, {Tesla.Adapter.Finch, name: MyFinch}
# set per module
defmodule MyClient do
def client do
Tesla.client([], {Tesla.Adapter.Finch, name: MyFinch})
end
endAdapter specific options
:name- The:nameprovided to Finch (required).:response- Expected response type. Defines the Finch request type to use. Supported values::stream- Streams the response usingFinch.stream/5for the request.nilor not specified - Responds without streaming usingFinch.request/3.
Streamed response failures
When response: :stream is used, failures that happen after the response
headers arrived cannot be returned as {:error, reason}, because the
request already succeeded from the caller point of view. Such failures raise
Tesla.Error while the body stream is being consumed, so that a truncated
response is never mistaken for a complete one:
try do
Enum.each(env.body, &handle_chunk/1)
rescue
e in Tesla.Error ->
# e.reason is, for example, :closed or :timeout
{:error, e.reason}
endWaiting longer than :receive_timeout for the next chunk raises with reason
:timeout. A server that ends the response early without failing the
connection is not an error, and the stream simply ends.
Finch build options
:unix_socket- Path to a Unix domain socket to connect to instead of the URL host/port. The URL scheme still determines whether HTTP or HTTPS is used.:pool_tag- The tag to use when selecting which pool to use for this request. Defaults to:default. See Finch - Pool Tagging.
Finch request options
:pool_timeout- This timeout is applied when a connection is checked out from the pool. Default value is5_000.:receive_timeout- The maximum time to wait for each chunk to arrive before returning an error. Default value is15_000.:request_timeout- The maximum time to wait for a complete response before returning an error. Only applies to HTTP/1. Default value is:infinity.:pool_strategy- Determines which shard handles the request when the pool has multiple shards (count > 1). Default selection is random.