Skip to main content

Crate reqwest_sse

Crate reqwest_sse 

Source
Expand description

reqwest-sse is a lightweight Rust library that extends reqwest by adding native support of Server-Sent Events (SSE) . 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 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

Traits§

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

Type Aliases§

ServerSentEvents
Represents a stream of Server-Sent Events.