Expand description
Session management
This module provides a session management system that allows you to store and retrieve session data.
§Examples
use cot::RequestHandler;
use cot::html::Html;
use cot::router::{Route, Router};
use cot::session::Session;
use cot::test::TestRequestBuilder;
async fn my_handler(session: Session) -> cot::Result<Html> {
session.insert("user_name", "world".to_string()).await?;
let name: String = session
.get("user_name")
.await?
.expect("name was just added");
Ok(Html::new(format!("Hello, {}!", name)))
}
let request = TestRequestBuilder::get("/").with_session().build();
assert_eq!(
my_handler
.handle(request)
.await?
.into_body()
.into_bytes()
.await?,
"Hello, world!"
);Modules§
Structs§
- Session
- A session object.