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

Traits