Rocket Flex Session
Simple, extensible session library for Rocket applications.
Features
- Secure: Session cookies are encrypted using Rocket's built-in private cookies
- Flexible: Use a custom struct or HashMap as your session data. Multiple storage providers available, as well as support for custom storage implementations.
- Efficient: Uses Rocket's request-local cache to minimize backend calls
Quick Start
Add to your Cargo.toml:
[]
= "0.5"
= { = "0.2" }
Basic usage:
use routes;
use ;
async
Storage Options
- Memory (default) - In-memory storage, for local development
- Cookie - Client-side encrypted cookies, serialized using serde (
cookiefeature) - Redis - Redis-backed sessions via the fred crate (
redis_fredfeature) - SQL Database - Postgres and SQLite-backed sessions via sqlx (
sqlx_postgresandsqlx_sqlitefeatures) - Custom - Custom storage possible by implementing the
SessionStoragetrait
Request Guard Pattern
Build authentication and authorization layers using Rocket's request guard system:
Documentation
See the full documentation for detailed usage examples, configuration options, and common patterns.
License
This project is licensed under the MIT license.