5 unstable releases

0.3.2 Jul 30, 2020
0.3.1 Mar 4, 2020
0.3.0 Mar 2, 2020
0.2.0 Jan 22, 2020
0.1.0 Dec 23, 2019

#1234 in Web programming

Download history 8959/week @ 2025-08-27 6180/week @ 2025-09-03 6553/week @ 2025-09-10 8419/week @ 2025-09-17 7525/week @ 2025-09-24 9147/week @ 2025-10-01 8169/week @ 2025-10-08 11416/week @ 2025-10-15 9787/week @ 2025-10-22 11629/week @ 2025-10-29 8950/week @ 2025-11-05 13708/week @ 2025-11-12 14002/week @ 2025-11-19 11567/week @ 2025-11-26 18081/week @ 2025-12-03 15470/week @ 2025-12-10

61,655 downloads per month
Used in 25 crates (3 directly)

MPL-2.0 license

33KB
757 lines

A futures_codec that encodes and decodes Server-Sent Event/Event Sourcing streams.

It emits or serializes full messages, and the meta-message retry:.

Examples

use sse_codec::{decode_stream, Event};
use futures::stream::TryStreamExt; // for try_next()

let response = surf::get("https://some-site.com/events").await?;
let mut events = decode_stream(response);

while let Some(event) = events.try_next().await? {
    println!("incoming: {:?}", event);

    match event {
        Event::Retry { retry } => {
            // change a retry timer value or something
        }
        Event::Message { event, .. } if event == "stop" => {
            break;
        }
        Event::Message { id, event, data } => {
            if let Some(id) = id {
                // change the last event ID
            }
            // handle event here
        }
    }
}

EventSource tests from the web-platform-tests suite. See https://github.com/web-platform-tests/wpt/tree/master/eventsource


sse-codec

A futures_codec that encodes and decodes Server-Sent Event/Event Sourcing streams.

Documentation

On docs.rs.

Installation

With cargo-edit do:

cargo add sse-codec

Or in Cargo.toml:

[dependencies]
sse-codec = "0.3.2"
  • surf-sse - EventSource client based on Surf and sse-codec.

License

MPL-2.0

Dependencies

~3MB
~62K SLoC