Crate sse_stream

Crate sse_stream 

Source
Expand description

§SSE Stream

Crates.io Version Release status docs.rs

A SSE decoder/encoder for Http body

§Decode

const SSE_BODY: &str =
r#"
retry: 1000
event: userconnect
data: {"username": "bobby", "time": "02:33:48"}

data: Here's a system message of some kind that will get used
data: to accomplish some task.
"#;

let body = Full::<Bytes>::from(SSE_BODY);
let mut sse_body = SseStream::new(body);
async {
    while let Some(sse) = sse_body.next().await {
        println!("{:?}", sse.unwrap());
    }
};

§Encode


let stream = futures_util::stream::iter([
    Sse::default().event("1").data("....."),
    Sse::default().event("2").data("....."),
    Sse::default().event("3").data("....."),
])
.map(Result::<Sse, Infallible>::Ok);
let body = SseBody::new(stream);

Structs§

KeepAlive
Configure the interval between keep-alive messages, the content of each message, and the associated stream.
NeverTimer
Sse
SseBody
SseStream

Enums§

Error

Traits§

Timer

Type Aliases§

ByteStreamBody