Nadia. HTTPClient behaviour
(nadia v1.6.0)
View Source
Behaviour for Nadia HTTP adapters.
Custom adapters receive a Nadia.HTTPRequest and return either
{:ok, %Nadia.HTTPResponse{}} or {:error, reason}. Applications usually do
not call this module directly, but tests and custom transports may pass an
adapter module through Nadia.Client.new/1.
download/1 is optional so existing adapters remain compatible. Adapters
that implement it must stream through Nadia.HTTPDownloadRequest.sink,
disable redirects and retries, avoid whole-response buffering, and never log
or return the token-bearing request URL.
Summary
Functions
Streams a bounded file response through an adapter's optional capability.
Callbacks
@callback download(Nadia.HTTPDownloadRequest.t()) :: {:ok, Nadia.HTTPDownloadResponse.t()} | {:error, term()}
@callback post(Nadia.HTTPRequest.t()) :: {:ok, Nadia.HTTPResponse.t()} | {:error, term()}
Functions
@spec default_adapter() :: module()
@spec download(module(), Nadia.HTTPDownloadRequest.t()) :: {:ok, Nadia.HTTPDownloadResponse.t()} | {:error, term()}
Streams a bounded file response through an adapter's optional capability.
Existing post-only adapters remain valid. They return
{:error, :unsupported_http_adapter} when used for downloads.
@spec post(Nadia.HTTPRequest.t()) :: {:ok, Nadia.HTTPResponse.t()} | {:error, term()}
@spec post(module(), Nadia.HTTPRequest.t()) :: {:ok, Nadia.HTTPResponse.t()} | {:error, term()}