Module sse

Expand description

Server-Sent Events (SSE) support

§Server-Sent Events (SSE)

Server-Sent Events (SSE) is a simple and efficient mechanism for servers to push real-time updates to clients over HTTP. Unlike WebSockets, which provide full-duplex communication, SSE establishes a one-way channel from server to client using a long-lived HTTP connection.

Rama offers support for SSE both as a client and a server. As such you could even MITM proxy it.

Server IntoResponse support is also supported, including with Keep-Alive support. See https://ramaproxy.org/docs/rama/http/service/web/response/struct.Sse.html for more info.

Learn more about SSE at https://ramaproxy.org/book/sse.html.

§Examples

You can find ready-to-run examples demonstrating how to expose and consume SSE endpoints using Rama:

  • http_sse.rs Simple example showing how to expose an SSE endpoint with string data.
  • http_sse_json.rs Same as above, but emits structured JSON data using typed Rust structs.

These examples make use of Rama’s typed header support, such as LastEventId, which allows easy extraction of reconnect state to resume streams reliably.

§Datastar

Datastar helps you build reactive web applications with the simplicity of server-side rendering and the power of a full-stack SPA framework.

https://data-star.dev/

Rama has built-in support for 🚀 data-*. You can see it in action in Examples:

Rama rust docs:

§Code Origins

Some code in this repo is adapted from third party sources:

Modules§

datastar
🚀 data-* support for rama.
server
SSE types for servers.

Structs§

Event
Server-sent event
EventBuildError
EventDataJsonReader
EventDataLineReader for the EventDataRead implementation of any json-compatible DeserializeOwned.
EventDataMultiLineReader
EventDataLineReader for the EventDataRead implementation of Vec.
EventDataStringReader
EventDataLineReader for the EventDataRead implementation of String.
EventStream
A Stream of SSE’s used by the client.
JsonEventData
Wrapper used to create Json event data.

Traits§

EventDataLineReader
EventDataRead
Trait that can be implemented for a custom data type that is to be read (by a client).
EventDataWrite
Trait that can be implemented for a custom data type that is to be written (by a server).