Nadia.HTTPClient behaviour (nadia v1.6.1)

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

download(t)

(optional)
@callback download(Nadia.HTTPDownloadRequest.t()) ::
  {:ok, Nadia.HTTPDownloadResponse.t()} | {:error, term()}

post(t)

@callback post(Nadia.HTTPRequest.t()) :: {:ok, Nadia.HTTPResponse.t()} | {:error, term()}

Functions

adapter()

default_adapter()

@spec default_adapter() :: module()

download(adapter, request)

@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.

post(request)

@spec post(Nadia.HTTPRequest.t()) :: {:ok, Nadia.HTTPResponse.t()} | {:error, term()}

post(adapter, request)

@spec post(module(), Nadia.HTTPRequest.t()) ::
  {:ok, Nadia.HTTPResponse.t()} | {:error, term()}