Crate reqwest_sse

Crate reqwest_sse 

Source
Expand description

§reqwest-sse

reqwest-sse is a lightweight Rust library that extends reqwest by adding native support for handling Server-Sent Events (SSE) . It introduces the EventSource trait, which enhances reqwest’s Response type with an ergonomic .events() method. This method transforms the response body into an asynchronous Stream of SSE Events, enabling seamless integration of real-time event handling in applications using the familiar reqwest HTTP client and the StreamExt API.

§Example

use tokio_stream::StreamExt;

use reqwest_sse::EventSource;

#[tokio::main]
async fn main() {
    let mut events = reqwest::get("https://sse.test-free.online/api/story")
        .await.unwrap()
        .events()
        .await.unwrap();

    while let Some(Ok(event)) = events.next().await {
        println!("{event:?}");
    }
}

Modules§

error

Structs§

Event
Server-Sent Event representation.

Statics§

MIME_EVENT_STREAM
text/event-stream MIME type as HeaderValue.

Traits§

EventSource
A trait for consuming a Response as a Stream of Server-Sent Events (SSE).