Skip to main content

Crate eventsource_client

Crate eventsource_client 

Source
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§

ClientBuilder
ClientBuilder provides a series of builder methods to easily construct a Client.
Event
HeaderError
Error type for invalid response headers encountered in ResponseDetails.
ReconnectOptions
Configuration for a Client’s reconnect behaviour.
ReconnectOptionsBuilder
Builder for ReconnectOptions.
ReconnectingRequest
Response

Enums§

Error
Error type returned from this library’s functions.
SSE

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.

Type Aliases§

BoxStream
Represents a Pin’d Send + Sync stream, returned by Client’s stream method.
Result