vend1k personal
Examples

Chat Walkthrough

Real-time messaging over SSE / WebSockets.

The Chat example showcases real-time messaging using Server-Sent Events (SSE) or WebSockets managed by Hono and rendered in Next.js.

Implementation steps

Establish a stream endpoint

Expose an event streaming endpoint on the API at /api/chat/stream.

Connect from the client

On the client, initiate an EventSource connection to that endpoint.

Post messages

Post messages using standard fetch requests that dispatch events into the API queue, which then fan out to connected listeners.

SSE is the simplest option for one-directional server-to-client updates. Reach for WebSockets only when you need bidirectional, low-latency messaging.

On this page