[][src]Crate actix_sled_session

Actix Sled Session

An Actix Web Session Backend using the Sled embedded database

This session backend sets an cookie with a unique ID for each incoming request that doesn't already have an ID set, and uses that ID as a key to look up session data from a Sled tree.

Usage

Update your Cargo.toml

[dependencies]
actix = "0.8"
actix-sled-session = "0.1"
actix-web = "1.0"

Use it in your project

use actix::System;
use actix_web::{web, App, HttpServer};
use actix_sled_session::{Session, SledSession};

fn index(session: Session) -> String {
    if let Ok(Some(item)) = session.get::<usize>("item") {
        println!("item, {}", item);
        session.clear();
        return format!("Got item, {}", item);
    }

    let _ = session.set::<usize>("item", 3);
    String::from("Set item!")
}

let sys = System::new("example");
let session_backend = SledSession::new_default()?;

HttpServer::new(move || {
    App::new()
        .wrap(session_backend.clone())
        .route("/", web::get().to(index))
})
    .bind("127.0.0.1:9876")?
    .start();

// Commented to prevent never-ending tests
// sys.run()?;

Structs

Session

The high-level interface you use to modify session data.

SledSession

The session middleware