eventsource-client

A tokio-based Server-Sent Events (SSE) client for Rust with automatic reconnection.

Library
Cargo
v0.18.0
113stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
69/100Good
Development Activity64
Maintenance56
Community76
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
78/100Good
Architecture82
Code Quality80
Innovation68
Learning Curve78

eventsource-client is a Rust implementation of the Server-Sent Events (SSE) protocol, also known as EventSource. It connects to an HTTP endpoint that streams text/event-stream data and exposes each event as an item in an asynchronous stream, handling the wire-format parsing, buffering, and event dispatch for you.

Built on tokio and maintained by LaunchDarkly as the transport underpinning their feature-flag SDKs, the client supports custom request headers for authenticated endpoints, retry on failed connections, and automatic reconnection with exponential backoff when a stream is interrupted. A fluent ClientBuilder API makes configuring and consuming a resilient event stream straightforward.

What You Get

  • A tokio-based async SSE client exposing events as a futures Stream
  • A fluent ClientBuilder for setting the URL, custom headers, and retry configuration
  • Automatic reconnection with exponential backoff when a stream drops
  • A compliant event-stream parser handling multi-line data, event types, and last-event-id

Common Use Cases

  • Consuming a Server-Sent Events feed from an HTTP API in a Rust service
  • Powering an SDK that receives streamed configuration or feature-flag updates
  • Subscribing to real-time server push notifications without WebSockets
  • Maintaining a long-lived, self-healing event stream that survives network interruptions

Under The Hood

Architecture - The crate is organized as a small set of focused modules under eventsource-client/src: client.rs implements the ClientBuilder and the streaming Client, config.rs holds connection and reconnection settings, event_parser.rs decodes the text/event-stream wire format into events, retry.rs implements the backoff strategy, and response.rs/error.rs model HTTP responses and failures. Consuming code drives everything through the stream() method, which yields a futures::Stream of parsed events while an internal state machine reconnects on interruption.

Tech Stack - Written almost entirely in Rust (99%), the client is built on tokio for async I/O and the futures ecosystem for its Stream abstraction, with an HTTP layer for the underlying request. It follows a stated MSRV policy tracking the latest stable Rust plus the two prior minor releases.

Code Quality - The codebase is modular with clear separation between parsing, retry, and client concerns. It ships an event_parser with dedicated logic for the SSE format and is backed by contract tests (a contract-tests harness) plus CI and a coverage script, indicating attention to correctness against the protocol specification.

API Design - The public surface is a compact, ergonomic builder: ClientBuilder::for_url(...).header(...).build() then .stream(). This keeps boilerplate minimal for the common case while still exposing reconnection and header configuration. The README notes the project is an early-stage release with an API that may still change, so some churn across minor versions is expected.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search