Pixir.Provider.Transport behaviour (pixir v0.1.0)

Copy Markdown View Source

The seam between Pixir.Provider and the network, so the SSE parsing can be tested without real HTTP. A transport streams an HTTP request and invokes fun for each low-level chunk — mirroring Finch.stream/5's shape:

fun.({:status, integer}, acc)
fun.({:headers, [{k, v}]}, acc)
fun.({:data, binary}, acc)

Returns {:ok, acc} or {:error, reason}. Pixir.Provider also accepts a plain 3-arity function in place of a module implementing this behaviour.

Summary

Types

chunk()

@type chunk() :: {:status, non_neg_integer()} | {:headers, list()} | {:data, binary()}

http_request()

@type http_request() :: %{
  method: atom(),
  url: String.t(),
  headers: [{String.t(), String.t()}],
  body: iodata()
}

Callbacks

stream(http_request, acc, function)

@callback stream(http_request(), acc, (chunk(), acc -> acc)) ::
  {:ok, acc} | {:error, term()}
when acc: term()