# `Urchin.Dispatcher`
[🔗](https://github.com/urth-inc/urchin/blob/v0.4.0/lib/urchin/dispatcher.ex#L1)

Routes decoded JSON-RPC requests to `Urchin.Server` callbacks and shapes their return
values into JSON-RPC result maps.

A method is only honoured when the server module exports the matching callback;
otherwise a JSON-RPC "method not found" error is returned. User exceptions are
rescued and converted to errors so transport processes never crash on handler bugs.

# `handle_request`

```elixir
@spec handle_request(module(), String.t(), map(), Urchin.Context.t()) ::
  {:ok, map()} | {:error, Urchin.Error.t()}
```

Handles an operational (post-initialization) request, returning `{:ok, result_map}`
or `{:error, Urchin.Error.t()}`.

# `initialize`

```elixir
@spec initialize(module(), map(), Urchin.Context.t()) ::
  {:ok, map(), map()} | {:error, Urchin.Error.t()}
```

Handles an `initialize` request.

Returns `{:ok, result_map, session_meta}` where `session_meta` carries the
negotiated protocol version and the client's declared info/capabilities, or
`{:error, Urchin.Error.t()}`.

---

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