Module afire::server_sent_events
source · Expand description
Server-sent event (SSE) support.
Example
server.route(Method::GET, "/sse", |req| {
let stream = req.sse().unwrap();
for i in 0..10 {
stream.send("update", i.to_string());
thread::sleep(Duration::from_secs(1));
}
Response::end()
});
Then in the browser you can connect to the event stream with JavaScript using the EventSource
API:
const events = new EventSource("/sse");
events.addEventListener("update", (event) => {
console.log(event.data);
});
Structs
- An event that can be sent as a server-sent event.
- A server-sent event stream.
Traits
- A trait for initiating a SSE connection on a request.