multiple_routes/
multiple_routes.rs1use warp::{Filter, Rejection};
2use warp_sessions::{MemoryStore, SessionWithStore};
3
4#[tokio::main]
5async fn main() {
6 let session_store = MemoryStore::new();
7
8 let route_get = warp::get()
9 .and(warp::path!("test"))
10 .and(warp_sessions::request::with_session(
11 session_store.clone(),
12 None,
13 ))
14 .and_then(
15 move |session_with_store: SessionWithStore<MemoryStore>| async move {
16 Ok::<_, Rejection>((
17 warp::reply::html("<html></html>".to_string()),
18 session_with_store,
19 ))
20 },
21 )
22 .untuple_one()
23 .and_then(warp_sessions::reply::with_session);
24
25 let route_post = warp::post()
26 .and(warp::path!("test"))
27 .and(warp_sessions::request::with_session(
28 session_store.clone(),
29 None,
30 ))
31 .and_then(
32 move |session_with_store: SessionWithStore<MemoryStore>| async move {
33 Ok::<_, Rejection>((
34 warp::reply::html("<html></html>".to_string()),
35 session_with_store,
36 ))
37 },
38 )
39 .untuple_one()
40 .and_then(warp_sessions::reply::with_session);
41
42 let port = 8080;
44 println!("starting server listening on ::{}", port);
45 warp::serve(route_get.or(route_post))
46 .run(([0, 0, 0, 0], port))
47 .await;
48}