1 use futures_util::{FutureExt, StreamExt};
6 // GET /hello/warp => 200 OK with body "Hello, warp!"
7 let hello = warp::path!("hello" / String)
8 .and(warp::header::<String>("user-agent"))
9 .map(|name, agent| format!("Hello, {} from {}!", name, agent));
11 // websocat ws://127.0.0.1:3030/ws-echo
12 let echo = warp::path("ws-echo")
14 .map(|ws: warp::ws::Ws| {
15 ws.on_upgrade(|websocket| {
16 // echo all messages back
17 let (tx, rx) = websocket.split();
18 rx.forward(tx).map(|result| {
19 if let Err(e) = result {
20 eprintln!("websocket error: {:?}", e);
26 warp::serve(hello.or(echo))
27 .run(([127, 0, 0, 1], 3030))