#launchdarkly #feature-flags #feature-toggles #eventsource #server-sent-events

eventsource-client

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

12 releases (breaking)

Uses new Rust 2021

0.10.1 Apr 14, 2022
0.10.0 Mar 23, 2022
0.9.0 Mar 15, 2022
0.7.0 Aug 25, 2021
0.2.0 Jul 24, 2019

#737 in Network programming

Download history 304/week @ 2022-06-14 325/week @ 2022-06-21 360/week @ 2022-06-28 342/week @ 2022-07-05 551/week @ 2022-07-12 514/week @ 2022-07-19 738/week @ 2022-07-26 461/week @ 2022-08-02 499/week @ 2022-08-09 647/week @ 2022-08-16 658/week @ 2022-08-23 584/week @ 2022-08-30 443/week @ 2022-09-06 797/week @ 2022-09-13 1068/week @ 2022-09-20 1217/week @ 2022-09-27

3,555 downloads per month
Used in launchdarkly-server-sdk

Apache-2.0

295KB
1K SLoC

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 as es;

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

client
    .stream()
    .map_ok(|event| println!("got event: {:?}", event))
    .map_err(|err| eprintln!("error streaming events: {:?}", err));

(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).
  • Retry for failed connections.
  • Reconnection if connection is interrupted, with exponential backoff.

Stability

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

Dependencies

~5–13MB
~228K SLoC