2 releases (1 stable)

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

#14 in #surf

Download history 13/week @ 2024-02-18 33/week @ 2024-02-25 9/week @ 2024-03-03 13/week @ 2024-03-10 4/week @ 2024-03-17

59 downloads per month
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–11MB
~233K SLoC