#![allow(dead_code)] // use actix_session::{Session, SessionMiddleware, storage::CookieSessionStore}; use actix_web::{web, App, Error, HttpResponse, HttpServer, cookie::Key}; async fn index(session: Session) -> Result { // access session data if let Some(count) = session.get::("counter")? { session.insert("counter", count + 1)?; } else { session.insert("counter", 1)?; } Ok(HttpResponse::Ok().body(format!( "Count is {:?}!", session.get::("counter")?.unwrap() ))) } #[actix_web::main] async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new() .wrap( // create cookie based session middleware SessionMiddleware::builder(CookieSessionStore::default(), Key::from(&[0; 64])) .cookie_secure(false) .build() ) .service(web::resource("/").to(index)) }) .bind(("127.0.0.1", 8080))? .run() .await } //