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§
- Client
Builder - ClientBuilder provides a series of builder methods to easily construct a
Client
. - Event
- Header
Error - Error type for invalid response headers encountered in ResponseDetails.
- Reconnect
Options - Configuration for a
Client
’s reconnect behaviour. - Reconnect
Options Builder - Builder for
ReconnectOptions
. - Reconnecting
Request - Response
Enums§
Constants§
- DEFAULT_
REDIRECT_ LIMIT - Maximum amount of redirects that the client will follow before giving up, if not overridden via ClientBuilder::redirect_limit.
Traits§
- Client
- Client is the Server-Sent-Events interface. This trait is sealed and cannot be implemented for types outside this crate.