#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 52/week @ 2024-01-08 44/week @ 2024-01-15 45/week @ 2024-01-22 33/week @ 2024-01-29 52/week @ 2024-02-05 48/week @ 2024-02-12 60/week @ 2024-02-19 86/week @ 2024-02-26 69/week @ 2024-03-04 77/week @ 2024-03-11 73/week @ 2024-03-18 84/week @ 2024-03-25 108/week @ 2024-04-01 52/week @ 2024-04-08 61/week @ 2024-04-15 53/week @ 2024-04-22

287 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