🎨 Overview
This crate provides sessions, key-value pairs associated with a site
visitor, as a tower middleware.
It offers:
- Pluggable Storage Backends: Bring your own backend simply by
implementing the
SessionStoretrait, fully decoupling sessions from their storage. - An
axumExtractor forSession: Applications built withaxumcan useSessionas an extractor directly in their handlers. This makes using sessions as easy as includingSessionin your handler. - Common Backends Out-of-the-Box:
RedisStore, SQLx (SqliteStore,PostgresStore,MySqlStore), andMongoDBStorestores are available via their respective feature flags. - Layered Caching: With
CachingSessionStore, applications can leverage a cache such asMokaStoreto reduce roundtrips to the store when loading sessions. - Simple Key-Value Interface: Sessions offer a key-value interface that
supports native Rust types. So long as these types are
Serializeand can be converted to JSON, it's straightforward to insert, get, and remove any value. - Strongly-Typed Sessions: Strong typing guarantees are easy to layer on top of this foundational key-value interface.
This crate's session implementation is inspired by the Django sessions middleware and it provides a transliteration of those semantics.
User authentication
For managing user authentication and authorization, please see axum-login.
📦 Install
To use the crate in your project, add the following to your Cargo.toml file:
[]
= "0.5.0"
🤸 Usage
axum Example
use SocketAddr;
use ;
use StatusCode;
use ;
use Duration;
use ServiceBuilder;
use ;
const COUNTER_KEY: &str = "counter";
;
async
async
You can find this example as well as other example projects in the example directory.
[!NOTE] See the crate documentation for more usage information.
🦺 Safety
This crate uses #![forbid(unsafe_code)] to ensure everything is implemented in 100% safe Rust.
🛟 Getting Help
We've put together a number of examples to help get you started. You're also welcome to open a discussion and ask additional questions you might have.
👯 Contributing
We appreciate all kinds of contributions, thank you!