Event Iterator
Server-Sent Events (SSE) with out-of-the-box support in oRPC
The event iterator in oRPC provides built-in support for streaming responses using Server-Sent Events (SSE) without any extra configuration. This makes it easy to build real-time, event-driven APIs.
Example Usage
The following example demonstrates how to create a streaming endpoint that continuously sends events to the client:
Key Concepts
-
lastEventId
:
This parameter represents the ID of the last event received by the client. When reconnecting, the client can send this ID so that the server can resume streaming from where it left off. -
withEventMeta
:
This helper function attaches additional metadata (such asid
andretry
) to an event. This metadata is useful for controlling the behavior of SSE, for example:id
: A unique identifier for the event. Last event id is used when reconnecting.retry
: The suggested reconnection delay (in milliseconds) if the connection is lost.