Crate axum_flash[][src]

Expand description

One-time notifications (aka flash messages) for axum.

Flash messages are stored in signed cookies managed by tower-cookies. This means if your app is otherwise also using cookies those should be managed by tower-cookies as well since it overrides response headers.

Example

use axum::{
    response::{IntoResponse, Redirect},
    routing::get,
    Router,
};
use axum_flash::{IncomingFlashes, Flash, Key};

// This should probably come from configuration
let key = Key::generate();

let app = Router::new()
    .route("/", get(root))
    .route("/set-flash", get(set_flash))
    .layer(axum_flash::layer(key).with_cookie_manager());

async fn root(flash: IncomingFlashes) -> impl IntoResponse {
    for (level, text) in flash {
        // ...
    }
}

async fn set_flash(mut flash: Flash) -> impl IntoResponse {
    flash.debug("Hi from flash!");
    Redirect::to("/".parse().unwrap())
}

Re-exports

pub use cookie::Key;

Modules

Extractor for incoming flash messages.

Middleware necessary for axum_flash to work.

Structs

Extractor for setting outgoing flash messages.

Extractor for incoming flash messages.

Enums

Verbosity level of a flash message.

Functions

Layer that applies the necessary middleware for axum_flash to work.