Expand description
Client for the Server-Sent Events protocol (aka EventSource).
This library provides SSE protocol support but requires you to bring your own
HTTP transport. See the examples/ directory for reference implementations using
popular HTTP clients like hyper and reqwest.
§Getting Started
ⓘ
use futures::TryStreamExt;
use eventsource_client::{Client, ClientBuilder, SSE};
// You need to implement HttpTransport trait for your HTTP client
let transport = MyTransport::new();
let client = ClientBuilder::for_url("https://example.com/stream")?
.header("Authorization", "Bearer token")?
.build_with_transport(transport);
let mut stream = client.stream();
while let Some(event) = stream.try_next().await? {
match event {
SSE::Event(evt) => println!("Event: {}", evt.event_type),
SSE::Comment(comment) => println!("Comment: {}", comment),
SSE::Connected(_) => println!("Connected!"),
}
}§Implementing a Transport
See the [transport] module documentation for details on implementing
the HttpTransport trait.
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.