PhoenixDatastar.Plug (PhoenixDatastar v0.1.14)

Copy Markdown View Source

Plug for handling PhoenixDatastar requests.

Handles SSE streams and event dispatch:

  • GET /path/stream - Maintains SSE connection for server-pushed updates (live views)
  • POST /path/_event/:event - Handles events for all views

Summary

Functions

Handles incoming requests for Datastar views.

Initializes the plug with options.

Functions

call(conn, opts)

@spec call(
  Plug.Conn.t(),
  keyword()
) :: Plug.Conn.t()

Handles incoming requests for Datastar views.

Dispatches based on HTTP method:

  • GET: SSE stream connection
  • POST: Event dispatch to GenServer

init(opts)

@spec init(keyword()) :: keyword()

Initializes the plug with options.

Options

  • :view - The view module to handle requests. Required for SSE streams, optional for the global event endpoint.