2 releases (1 stable)

1.0.0 Nov 7, 2020
1.0.0-alpha.0 Jul 30, 2020

#18 in #event-source


Used in eventstreams

MPL-2.0 license

23KB
180 lines

surf-sse

Server-Sent Event/Event Sourcing client using surf.

Documentation

On docs.rs.

Installation

In Cargo.toml:

[dependencies]
surf-sse = "1.0.0"

License

MPL-2.0


lib.rs:

An implementation of the EventSource API using Surf.

Surf Cargo Features

surf-sse wraps the Surf library. By default, surf-sse uses the default Surf features. If you are using a non-default Surf client implementation or feature set, you can disable surf-sse's default feature:

surf = { version = "*", features = ["hyper-client"] }
surf-sse = { version = "*", default-features = false }

This way, surf-sse will also use the "hyper-client" feature.

Logging

surf-sse uses the log crate for some rudimentary connection logging. If you need to debug an EventSource connection, enable trace logging for the surf-sse target. For example, with env_logger:

RUST_LOG=surf-sse=trace \
cargo run

Examples

#
use futures_util::stream::TryStreamExt; // for try_next()
use surf_sse::EventSource;

let mut events = EventSource::new("https://announce.u-wave.net/events".parse().unwrap());

while let Some(message) = events.try_next().await.unwrap() {
    dbg!(message);
}
#

Dependencies

~8–12MB
~203K SLoC