[−][src]Module warp::filters::sse
Server-Sent Events (SSE)
Example
use std::time::Duration; use futures::stream::iter_ok; use warp::{Filter, sse::ServerSentEvent}; let app = warp::path("push-notifications").and(warp::sse()).map(|sse: warp::sse::Sse| { let events = iter_ok::<_, ::std::io::Error>(vec![ warp::sse::data("unnamed event").into_a(), ( warp::sse::event("chat"), warp::sse::data("chat message"), ).into_a().into_b(), ( warp::sse::id(13), warp::sse::event("chat"), warp::sse::data("other chat message\nwith next line"), warp::sse::retry(Duration::from_millis(5000)), ).into_b().into_b(), ]); sse.reply(warp::sse::keep_alive().stream(events)) });
Each field already is event which can be sent to client. The events with multiple fields can be created by combining fields using tuples.
See also the EventSource API, which specifies the expected behavior of Server Sent Events.
Structs
KeepAlive | Configure the interval between keep-alive messages, the content of each message, and the associated stream. |
Sse | Extracted by the |
Traits
ServerSentEvent | Server-sent event message |
Functions
comment | Comment field (": |
data | Data field(s) ("data: |
event | Event name field ("event: |
id | Identifier field ("id: |
json | Data field with JSON content ("data: |
keep_alive | Keeps event source connection alive when no events sent over a some time. |
last_event_id | Gets the optional last event id from request. Typically this identifier represented as number or string. |
retry | Retry timeout field ("retry: |
sse | Creates a Server-sent Events filter. |