#sse #eventsource #stream #parse #event

no-std eventsource-stream

A basic building block for building an Eventsource from a Stream of bytes

2 releases

✓ Uses Rust 2018 edition

0.1.1 Jun 28, 2020
0.1.0 Jun 27, 2020

#63 in HTTP client


Used in 2 crates (via reqwest-eventsource)

MIT/Apache

13KB
259 lines

eventsource-stream

A basic building block for building an Eventsource from a Stream of bytes array like objects. To learn more about Server Sent Events (SSE) take a look at the MDN docs

Example

let mut stream = reqwest::Client::new()
    .get("http://localhost:7020/notifications")
    .send()
    .await?
    .bytes_stream()
    .eventsource();

while let Some(thing) = stream.next().await {
   println!("{:?}", thing);
}

License: MIT OR Apache-2.0


lib.rs:

A basic building block for building an Eventsource from a Stream of bytes array like objects. To learn more about Server Sent Events (SSE) take a look at the MDN docs

Example

let mut stream = reqwest::Client::new()
    .get("http://localhost:7020/notifications")
    .send()
    .await?
    .bytes_stream()
    .eventsource();


while let Some(event) = stream.next().await {
    match event {
        Ok(event) => println!(
            "received: {:?}: {}",
            event.event,
            String::from_utf8_lossy(&event.data)
        ),
        Err(e) => eprintln!("error occured: {}", e),
    }
}

Dependencies

~0.5–1MB
~20K SLoC