# `Dstar.Plugs.Dispatch`
[🔗](https://github.com/ricotrevisan/dstar/blob/v0.3.3/lib/dstar/plugs/dispatch.ex#L1)

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.
- `:max_signal_bytes` — Maximum raw signal JSON size (default `1_000_000`).
  If `Plug.Parsers` runs first, configure its `:length` and `:read_length`
  to the same or a smaller value.

Malformed and non-object signal payloads receive 400, and oversized raw
payloads receive 413. Dispatch returns those responses before calling the
handler, so an SSE response has not yet started.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
