Crate eventsource_client
source ·Expand description
Client for the Server-Sent Events protocol (aka EventSource).
use futures::{TryStreamExt};
use eventsource_client::{Client, SSE};
let mut client = eventsource_client::ClientBuilder::for_url("https://example.com/stream")?
.header("Authorization", "Basic username:password")?
.build();
let mut stream = Box::pin(client.stream())
.map_ok(|event| match event {
SSE::Comment(comment) => println!("got a comment event: {:?}", comment),
SSE::Event(evt) => println!("got an event: {}", evt.event_type),
SSE::Connected(_) => println!("got connected")
})
.map_err(|e| println!("error streaming events: {:?}", e));
Structs§
- ClientBuilder provides a series of builder methods to easily construct a
Client
. - Error type for invalid response headers encountered in ResponseDetails.
- Configuration for a
Client
’s reconnect behaviour. - Builder for
ReconnectOptions
.
Enums§
- Error type returned from this library’s functions.
Constants§
- Maximum amount of redirects that the client will follow before giving up, if not overridden via ClientBuilder::redirect_limit.
Traits§
- Client is the Server-Sent-Events interface. This trait is sealed and cannot be implemented for types outside this crate.