axum/examples
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
..
async-graphql Replace hyper::Server with axum::Server in docs (#118) 2021-08-04 15:38:51 +02:00
chat Add chat example (#78) 2021-08-01 22:42:34 +02:00
self_signed_certs Add TLS example (with rustls) (#57) 2021-08-01 08:32:47 +02:00
sse Server-Sent Events (#75) 2021-08-01 21:49:17 +02:00
templates Add HTML template example (#17) 2021-06-13 13:58:12 +02:00
websocket Add support for websockets (#3) 2021-06-12 20:50:30 +02:00
404.rs Handle METHOD_NOT_ALLOWED in 404 example (#131) 2021-08-06 01:15:23 +02:00
chat.rs Change WebSocket API to use an extractor (#121) 2021-08-07 17:26:23 +02:00
error_handling_and_dependency_injection.rs Implement path extractor (#124) 2021-08-06 10:17:57 +02:00
form.rs Simplify tracing-subscriber initialization (#128) 2021-08-05 19:43:03 +02:00
hello_world.rs Simplify tracing-subscriber initialization (#128) 2021-08-05 19:43:03 +02:00
key_value_store.rs Implement path extractor (#124) 2021-08-06 10:17:57 +02:00
multipart_form.rs Simplify tracing-subscriber initialization (#128) 2021-08-05 19:43:03 +02:00
README.md docs: add community showcase (#126) 2021-08-05 13:47:19 +02:00
sessions.rs Simplify tracing-subscriber initialization (#128) 2021-08-05 19:43:03 +02:00
sse.rs Simplify tracing-subscriber initialization (#128) 2021-08-05 19:43:03 +02:00
static_file_server.rs Simplify tracing-subscriber initialization (#128) 2021-08-05 19:43:03 +02:00
templates.rs Implement path extractor (#124) 2021-08-06 10:17:57 +02:00
testing.rs Simplify tracing-subscriber initialization (#128) 2021-08-05 19:43:03 +02:00
tls_rustls.rs Simplify tracing-subscriber initialization (#128) 2021-08-05 19:43:03 +02:00
todos.rs Implement path extractor (#124) 2021-08-06 10:17:57 +02:00
tokio_postgres.rs Simplify tracing-subscriber initialization (#128) 2021-08-05 19:43:03 +02:00
unix_domain_socket.rs Simplify tracing-subscriber initialization (#128) 2021-08-05 19:43:03 +02:00
versioning.rs Implement path extractor (#124) 2021-08-06 10:17:57 +02:00
websocket.rs Change WebSocket API to use an extractor (#121) 2021-08-07 17:26:23 +02:00

Examples

Community showcase

  • Houseflow: House automation platform written in Rust.