Commit graph

6 commits

Author SHA1 Message Date
David Pedersen
4194cf70da
Change WebSocket API to use an extractor (#121)
Fixes https://github.com/tokio-rs/axum/issues/111

Example usage:

```rust
use axum::{
    prelude::*,
    extract::ws::{WebSocketUpgrade, WebSocket},
    response::IntoResponse,
};

let app = route("/ws", get(handler));

async fn handler(ws: WebSocketUpgrade) -> impl IntoResponse {
    ws.on_upgrade(handle_socket)
}

async fn handle_socket(mut socket: WebSocket) {
    while let Some(msg) = socket.recv().await {
        let msg = if let Ok(msg) = msg {
            msg
        } else {
            // client disconnected
            return;
        };

        if socket.send(msg).await.is_err() {
            // client disconnected
            return;
        }
    }
}
```
2021-08-07 17:26:23 +02:00
David Pedersen
5c12328892
Replace hyper::Server with axum::Server in docs (#118)
* Replace `hyper::Server` with `axum::Server` in docs

* Change readme as well
2021-08-04 15:38:51 +02:00
Grzegorz Baranski
4e9b38ddf9
Use tuple destructuring in chat example (#105) 2021-08-03 22:21:18 +02:00
David Pedersen
9fbababc3a
Make it clear how to run all examples (#92)
* Handle errors in websocket example

* Make it clear how to run all examples
2021-08-02 23:09:09 +02:00
Javier Viola
c6b7ad0f33
Add chat example documentation. (#85) 2021-08-02 21:42:10 +02:00
programatik29
ffefb3455c
Add chat example (#78) 2021-08-01 22:42:34 +02:00