3 releases

0.5.0-rc Mar 20, 2020
0.5.0-beta Mar 4, 2020
0.5.0-alpha Mar 3, 2020

#590 in #web-framework

MIT license

80KB
1.5K SLoC

Stable Test codecov Rust Docs Crate version Download Version License: MIT

Roa-websocket

This crate provides a websocket endpoint.

Example

use futures::StreamExt;
use roa_router::{Router, RouterError};
use roa_websocket::Websocket;
use roa_core::{App, SyncContext};
use roa_core::http::Method;

# fn main() -> Result<(), RouterError> {
let mut app = App::new(());
let mut router = Router::new();
router.end(
    "/chat",
    [Method::GET],
    Websocket::new(|_ctx: SyncContext<()>, stream| async move {
        let (write, read) = stream.split();
        // echo
        if let Err(err) = read.forward(write).await {
            println!("forward err: {}", err);
        }
    }),
);
app.gate(router.routes("/")?);
Ok(())
# }

Dependencies

~13MB
~246K SLoC