🎨 Overview
This crate provides sessions, key-value pairs associated with a site
visitor, as a tower middleware.
It offers:
- Pluggable Storage Backends: Arbitrary storage backends are implemented
with 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:
RedisStoreand SQLx (SqliteStore,PostgresStore,MySqlStore) stores are available via their respective feature flags. - 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.
📦 Install
To use the crate in your project, add the following to your Cargo.toml file:
[]
= "0.1.0"
🤸 Usage
axum Example
use SocketAddr;
use ;
use StatusCode;
use ;
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.
See the crate documentation for more usage information.
🦺 Safety
This crate uses #![forbid(unsafe_code)] to ensure everything is implemented in 100% safe Rust.
👯 Contributing
We appreciate all kinds of contributions, thank you!