actix-sled-session

Crates.ioactix-sled-session
lib.rsactix-sled-session
version0.2.0
sourcesrc
created_at2019-09-17 23:39:36.02897
updated_at2019-10-16 16:33:35.127244
descriptionAn Actix Web Session Backend using the Sled embedded database
homepage
repositoryhttps://git.asonix.dog/Aardwolf/actix-sled-session
max_upload_size
id165565
size141,183
asonix (asonix)

documentation

README

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.2"
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!")
}

fn main() -> Result<(), failure::Error> {
    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();

    sys.run()?;
    Ok(())
}

Contributing

Unless otherwise stated, all contributions to this project will be licensed under the CSL with the exceptions listed in the License section of this file.

License

This work is licensed under the Cooperative Software License. This is not a Free Software License, but may be considered a "source-available License." For most hobbyists, self-employed developers, worker-owned companies, and cooperatives, this software can be used in most projects so long as this software is distributed under the terms of the CSL. For more information, see the provided LICENSE file. If none exists, the license can be found online here. If you are a free software project and wish to use this software under the terms of the GNU Affero General Public License, please contact me at asonix@asonix.dog and we can sort that out. If you wish to use this project under any other license, especially in proprietary software, the answer is likely no.

Commit count: 0

cargo fmt