One-time notification messages for Axum
open sourceMITself-hostablefree
axum-messages adds one-time notification messages, often called flash messages, to axum applications: a handler pushes a message before a redirect and the next request reads it once. It stores messages in a tower-sessions session, so an app that already uses tower-sessions adds it with one layer (MessagesManagerLayer) and a Messages extractor. Messages have Django-style levels (debug, info, success, warning and error) and can carry optional metadata. It's modelled on the Django messages framework, borrows from axum-flash's cookie-based approach and is written in safe Rust (#![forbid(unsafe_code)]).
Problems it solves
- show a 'saved successfully' notice on the page my Axum handler redirects to
- display an error message once after a form post fails and the user is redirected back
- flash messages in a Rust web app like Django's messages framework or Rails' flash
- pass a one-time notice from one request to the next without putting it in the URL
- my Axum app already uses tower-sessions and I want notifications stored in the same session
- tag notices as info, success, warning or error so my templates can style them differently
- attach extra data like a link or an ID to a one-time notification in a Rust web app
Features
- Messages extractor for axum handlers
- MessagesManagerLayer tower layer
- stored in a tower-sessions session
- debug, info, success, warning and error levels
- optional metadata on each message
- messages read once, then cleared
- forbids unsafe code
