eventsource-client 0.1.0

Client for the Server-Sent Events protocol (aka EventSource)
Documentation

eventsource-client

Client for the Server-Sent Events protocol (aka EventSource).

Requirements

Requires tokio.

Usage

Example that just prints the type of each event received:

use eventsource_client::Client;

let mut client = Client::for_url("https://example.com/stream")?
    .header("Authorization", "Basic username:password")?
    .build();

client.stream()
    .for_each(|event| {
      Ok(println!("got an event: {}", event.event_type))
    })
    .map_err(|e| println!("error streaming events: {:?}", e));

(Some boilerplate omitted for clarity; see examples directory for complete, working code.)

Features

  • tokio-based streaming client.
  • Supports setting custom headers on the HTTP request (e.g. for endpoints requiring authorization).

Not yet implemented

  • Retry for failed connections.
  • Reconnection if connection is interrupted.

Stability

Early stage release for feedback purposes. May contain bugs or performance issues. API subject to change.