[][src]Crate async_session

Async HTTP sessions.

This crate provides a generic interface between cookies and storage backends to create a concept of sessions. It provides an interface that can be used to encode and store sessions, and decode and load sessions generating cookies in the process.


This module has not been vetted for security purposes, and in particular the in-memory storage backend is wildly insecure. Please thoroughly validate whether this crate is a match for your intended use case before relying on it in any sensitive context.


use async_session::mem::MemoryStore;
use async_session::{Session, SessionStore};
use cookie::CookieJar;

// Init a new session store we can persist sessions to.
let mut store = MemoryStore::new();

// Create a new session.
let sess = store.create_session();

// Persist the session to our backend, and store a cookie
// to later access the session.
let mut jar = CookieJar::new();
let sess = store.store_session(sess, &mut jar).await?;

// Retrieve the session using the cookie.
let sess = store.load_session(&jar).await?;
println!("session: {:?}", sess);



In-memory session store.



The main session type.



An async session backend.