11 releases

✓ Uses Rust 2018 edition

0.2.0 Jul 8, 2019
0.1.1 Jun 3, 2019
0.1.0 May 18, 2019
0.1.0-beta.2 Apr 28, 2019
0.1.0-alpha.2 Mar 30, 2019

#86 in HTTP server

Download history 71/week @ 2019-03-25 140/week @ 2019-04-01 171/week @ 2019-04-08 163/week @ 2019-04-15 197/week @ 2019-04-22 211/week @ 2019-04-29 196/week @ 2019-05-06 203/week @ 2019-05-13 233/week @ 2019-05-20 213/week @ 2019-05-27 383/week @ 2019-06-03 247/week @ 2019-06-10 298/week @ 2019-06-17 354/week @ 2019-06-24 343/week @ 2019-07-01

1,060 downloads per month
Used in 7 crates (2 directly)

MIT/Apache

428KB
9K SLoC

Session for actix web framework Build Status codecov crates.io Join the chat at https://gitter.im/actix/actix

Documentation & community resources


lib.rs:

User sessions.

Actix provides a general solution for session management. Session middlewares could provide different implementations which could be accessed via general session api.

By default, only cookie session backend is implemented. Other backend implementations can be added.

In general, you insert a session middleware and initialize it , such as a CookieSessionBackend. To access session data, Session extractor must be used. Session extractor allows us to get or set session data.

use actix_web::{web, App, HttpServer, HttpResponse, Error};
use actix_session::{Session, CookieSession};

fn index(session: Session) -> Result<&'static str, Error> {
    // access session data
    if let Some(count) = session.get::<i32>("counter")? {
        println!("SESSION value: {}", count);
        session.set("counter", count+1)?;
    } else {
        session.set("counter", 1)?;
    }

    Ok("Welcome!")
}

fn main() -> std::io::Result<()> {
# std::thread::spawn(||
    HttpServer::new(
        || App::new().wrap(
              CookieSession::signed(&[0; 32]) // <- create cookie based session middleware
                    .secure(false)
             )
            .service(web::resource("/").to(|| HttpResponse::Ok())))
        .bind("127.0.0.1:59880")?
        .run()
# );
# Ok(())
}

Dependencies

~20MB
~446K SLoC