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

Server-Sent Events framing helpers for the Streamable HTTP transport.

Event IDs are namespaced per stream (`<stream_id>:<seq>`) so the server can map a
`Last-Event-ID` back to the originating stream during resumption, as the transport
spec requires.

# `comment`

```elixir
@spec comment(String.t()) :: iodata()
```

Builds an SSE comment line, useful as a keep-alive heartbeat.

# `event_id`

```elixir
@spec event_id(String.t(), non_neg_integer()) :: String.t()
```

Builds a per-stream event id of the form `<stream_id>:<seq>`.

# `message`

```elixir
@spec message(String.t(), iodata()) :: iodata()
```

Formats a JSON-RPC message as an SSE event with the given id.

The JSON payload is emitted on a single `data:` line (JSON never contains raw
newlines once encoded).

# `parse_event_id`

```elixir
@spec parse_event_id(String.t()) :: {String.t(), non_neg_integer()} | :error
```

Parses a `Last-Event-ID` value into `{stream_id, seq}`.

Returns `:error` when the value is not a recognised per-stream id.

# `priming`

```elixir
@spec priming(String.t()) :: iodata()
```

Builds the priming event: an event id with an empty `data` field, sent first so the
client can immediately reconnect using that id as `Last-Event-ID`.

# `retry`

```elixir
@spec retry(non_neg_integer()) :: iodata()
```

Builds a `retry` directive instructing the client how long to wait before reconnecting.

---

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