Guide

WebSockets

H3 has built-in support for cross platform WebSocket and SSE.


H3 natively supports runtime agnostic WebSocket API using CrossWS.

You can define WebSocket handlers in your exisiting Event Handlers to define multiple websocket handlers, dynamically matched with your same route defenitions!
Read more in WebSocket in MDN.
Read more in CrossWS.
WebSockets support is currently experimental and available in nightly channel.

Usage

Example

You can use npx listhen --ws -w websocket.ts to run this example

Server Sent Events (SSE)

As an alternative to WebSockets, you can use Server-sent events.

H3 has a built-in API to create server-sent events using createEventStream(event) utility.

SSE support is currently experimental and available in nightly channel.

Example