Port for streaming HTTP transport.
Unlike the regular Transport port which returns complete responses, this port returns StreamResponse with an enumerable body for handling SSE (Server-Sent Events) and other streaming responses.
Implementation Requirements
Adapters implementing this behaviour should:
- Make an HTTP request with appropriate streaming headers
- Return a StreamResponse with an enumerable that yields events
- Handle connection lifecycle (cleanup on enumeration completion)
- Parse SSE events if content-type is
text/event-stream
Example Adapter
defmodule MyStreamAdapter do
@behaviour Pristine.Ports.StreamTransport
@impl true
def stream(%Request{} = request, %Context{} = context) do
# Make streaming HTTP request
# Parse SSE events
# Return StreamResponse
{:ok, %StreamResponse{stream: events, status: 200, headers: headers}}
end
end
Summary
Callbacks
Make a streaming HTTP request and return an enumerable of events.
Callbacks
@callback stream(Pristine.Core.Request.t(), Pristine.Core.Context.t()) :: {:ok, Pristine.Core.StreamResponse.t()} | {:error, term()}
Make a streaming HTTP request and return an enumerable of events.
Parameters
request- The request to sendcontext- Runtime context with configuration
Returns
{:ok, StreamResponse.t()}- Success with streaming response{:error, term()}- Error during connection or initial response
Notes
The returned stream is lazy - it will only fetch data as it is consumed. Callers should ensure they consume or close the stream to release resources.