#event-source #http #events #server-sent-events #header #http-request #thread

eventsource-threaded

Library for accessing EventSource/Server-Sent Events endpoints via threads with headers support

1 unstable release

0.1.0 Jan 9, 2021

#970 in HTTP server

Download history 21/week @ 2024-02-19 14/week @ 2024-02-26 17/week @ 2024-03-04 14/week @ 2024-03-11 9/week @ 2024-03-18 12/week @ 2024-03-25 47/week @ 2024-04-01

85 downloads per month
Used in 2 crates (via urbit-http-api)

MIT license

18KB
299 lines

EventSource-Threaded

EventSource-Threaded is a Rust library for reading from Server-Sent Events endpoints. It transparently sends HTTP requests on a separate thread and only exposes a stream of events to the user via a channel receiver. It handles automatic reconnection and parsing of the text/event-stream data format.

EventSource-Threaded is a fork of this EventSource library created by lluchs. The primary differences are:

  • The EventSource client is now threaded
  • Adding arbitrary header values is now supported (important for use cases where you need to set cookies for Authorization for example)
  • Minor renaming/removing methods/interface change

Examples

use eventsource-threaded::reqwest::Client;
use reqwest::Url;

fn main() {
    let receiver = EventSource::new(Url::parse("http://example.com").unwrap());
    loop {
        println!("Received Event: {:?}", receiver.recv());
    }

}

lib.rs:

EventSource-Threaded

EventSource-Threaded is a Rust library for reading from Server-Sent Events endpoints. It transparently sends HTTP requests on a separate thread and only exposes a stream of events to the user via a channel receiver. It handles automatic reconnection and parsing of the text/event-stream data format.

Examples

use eventsource-threaded::reqwest::Client;
use reqwest::Url;

fn main() {
    let receiver = EventSource::new(Url::parse("http://example.com").unwrap());
    loop {
        println!("Received Event: {:?}", receiver.recv());
    }
}

Dependencies

~2.6–7.5MB
~155K SLoC