# reqwest-sse
[![Made With Rust][made-with-rust]][rust]
[![Crates.io][badge-crates.io]][reqwest-sse-crates.io]
[![Docs.rs][badge-docs.rs]][reqwest-sse-docs.rs]
`reqwest-sse` is a lightweight Rust library that extends [reqwest](https://docs.rs/reqwest) by adding native support of
[Server-Sent Events (SSE)](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events).
It introduces the `EventSource` trait, which extends reqwest's `Response` type with an ergonomic `.events()` method.
This method transforms the response body into an asynchronous `Stream` of SSE `Event`s, enabling seamless integration
of real-time event handling in applications using the familiar reqwest HTTP client and the `StreamExt` API.
### Example
```rust
use tokio_stream::StreamExt;
use reqwest_sse::EventSource;
#[tokio::main]
async fn main() {
let mut events = reqwest::get("https://example.com/sse")
.await.unwrap()
.events()
.await.unwrap();
while let Some(Ok(event)) = events.next().await {
println!("{event:?}");
}
}
```
[rust]: https://www.rust-lang.org/
[made-with-rust]: https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust 'Made With Rust'
[badge-crates.io]: https://img.shields.io/badge/crates.io-v0.2.0-orange.svg?style=for-the-badge 'View on crates.rs'
[reqwest-sse-crates.io]: https://crates.io/crates/reqwest-sse
[badge-docs.rs]: https://img.shields.io/badge/docs.rs-reqwest--sse-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs 'Read doc on docs.rs'
[reqwest-sse-docs.rs]: https://docs.rs/reqwest-sse