#events #server-sent-events #sse #http #server-sent

uhttp_sse

Zero-copy, zero-allocation HTTP Server-Sent Events protocol

2 releases

Uses old Rust 2015

0.5.1 Feb 23, 2017
0.5.0 Jan 23, 2017

#23 in #server-sent-events

Download history 51/week @ 2023-12-13 53/week @ 2023-12-20 34/week @ 2023-12-27 42/week @ 2024-01-03 52/week @ 2024-01-10 43/week @ 2024-01-17 42/week @ 2024-01-24 35/week @ 2024-01-31 51/week @ 2024-02-07 60/week @ 2024-02-14 58/week @ 2024-02-21 84/week @ 2024-02-28 69/week @ 2024-03-06 80/week @ 2024-03-13 75/week @ 2024-03-20 80/week @ 2024-03-27

309 downloads per month
Used in 9 crates (via wick-http-client)

MIT license

8KB
95 lines

uhttp_sse -- HTTP Server-Sent Events protocol

Documentation

This crate provides a zero-copy, zero-allocation implementation of the Server-Sent Events (SSE) protocol for streaming events from an HTTP server.

The events can be written directly to a TcpStream or any other object that implements Write.

Example

use uhttp_sse::SseMessage;
use std::io::Write;

let mut buf = [0; 31];

{
    let mut sse = SseMessage::new(&mut buf[..]);
    write!(sse.event().unwrap(), "ping").unwrap();
    write!(sse.data().unwrap(), "abc").unwrap();
    write!(sse.data().unwrap(), "{}", 1337).unwrap();
}

// This would result in the "ping" event listener being triggered with the data
// payload "abc1337".
assert_eq!(&buf[..], b"event:ping\ndata:abc\ndata:1337\n\n");

Usage

This crate can be used through cargo by adding it as a dependency in Cargo.toml:

[dependencies]
uhttp_sse = "0.5.1"

and importing it in the crate root:

extern crate uhttp_sse;

No runtime deps