Dstar.Plugs.Dispatch (dstar v0.1.0)

Copy Markdown View Source

Dynamic event dispatch plug.

Routes POST /ds/:module/:event requests to handler modules. Each handler module implements handle_event(conn, event, signals).

Usage

# In your Phoenix router:
post "/ds/:module/:event", Dstar.Plugs.Dispatch, modules: [
  MyAppWeb.CounterHandler,
  MyAppWeb.TodoHandler
]

# Handler module — just a plain module with a function:
defmodule MyAppWeb.CounterHandler do
  def handle_event(conn, "increment", signals) do
    count = signals["count"] || 0

    conn
    |> Dstar.start()
    |> Dstar.patch_signals(%{count: count + 1})
  end
end

Options

  • :modules — Required. List of allowed handler modules.