HTTP.Adapter behaviour (http_fetch v1.0.0-rc.9)

Copy Markdown View Source

A two-stage request adapter for HTTP.fetch/2.

Pass adapter: {Module, configuration} (or adapter: Module). prepare/2 runs in the caller after Fetch input normalization and must return immutable context. execute/3 runs in the request's existing Promise worker. Adapters return an HTTP.Response or {:error, reason}; Fetch applies telemetry and the requested error mode. Adapter errors never fall back to socket transport.

Adapters own the resources they create and must register applicable streams with HTTP.RequestLifecycle.current/0. Simulated cleanup proves only those resources, not network or pool behavior.

Summary

Callbacks

execute(t, term, arg3)

@callback execute(HTTP.Request.t(), term(), pid() | nil) ::
  HTTP.Response.t() | {:error, term()}

prepare(t, term)

@callback prepare(HTTP.Request.t(), term()) :: {:ok, term()} | {:error, term()}