18 releases (11 breaking)

0.13.0 Jul 30, 2024
0.12.2 Dec 20, 2023
0.12.0 Nov 15, 2023
0.11.0 Nov 7, 2022
0.2.0 Jul 24, 2019

#16 in HTTP client

Download history 39565/week @ 2024-07-24 63998/week @ 2024-07-31 56240/week @ 2024-08-07 48722/week @ 2024-08-14 72196/week @ 2024-08-21 36143/week @ 2024-08-28 43157/week @ 2024-09-04 46444/week @ 2024-09-11 22685/week @ 2024-09-18 37452/week @ 2024-09-25 37757/week @ 2024-10-02 34722/week @ 2024-10-09 35288/week @ 2024-10-16 29937/week @ 2024-10-23 25565/week @ 2024-10-30 18450/week @ 2024-11-06

115,718 downloads per month
Used in 17 crates (12 directly)

Apache-2.0

300KB
1.5K SLoC

eventsource-client

Run CI

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–15MB
~204K SLoC