Skip to main content

eventsource_client/
lib.rs

1#![warn(rust_2018_idioms)]
2#![allow(clippy::result_large_err)]
3//! Client for the [Server-Sent Events] protocol (aka [EventSource]).
4//!
5//! ```
6//! use futures::{TryStreamExt};
7//! # use eventsource_client::Error;
8//! use eventsource_client::{Client, SSE};
9//! # #[tokio::main]
10//! # async fn main() -> Result<(), eventsource_client::Error> {
11//! let mut client = eventsource_client::ClientBuilder::for_url("https://example.com/stream")?
12//!     .header("Authorization", "Basic username:password")?
13//!     .build();
14//!
15//! let mut stream = Box::pin(client.stream())
16//!     .map_ok(|event| match event {
17//!         SSE::Comment(comment) => println!("got a comment event: {:?}", comment),
18//!         SSE::Event(evt) => println!("got an event: {}", evt.event_type),
19//!         SSE::Connected(_) => println!("got connected")
20//!     })
21//!     .map_err(|e| println!("error streaming events: {:?}", e));
22//! # while let Ok(Some(_)) = stream.try_next().await {}
23//! #
24//! # Ok(())
25//! # }
26//! ```
27//!
28//![Server-Sent Events]: https://html.spec.whatwg.org/multipage/server-sent-events.html
29//![EventSource]: https://developer.mozilla.org/en-US/docs/Web/API/EventSource
30
31mod client;
32mod config;
33mod error;
34mod event_parser;
35mod response;
36mod retry;
37
38pub use client::*;
39pub use config::*;
40pub use error::*;
41pub use event_parser::Event;
42pub use event_parser::SSE;
43pub use response::Response;