Request session extension for the Iron web framework.
session is a fast, convenient, and flexible extension for Iron Request. It allows saving/retriving data in to session, redis as the backend data repos.
```rust extern crate iron; extern crate session; extern crate rustc_serialize; use iron::prelude::; use session::;
// To run, $ cargo run --example simple // to use, $ curl "http://localhost:3000"
struct Account {
id: usize,
name: Option
fn main() { let mut chain = Chain::new(requesthandler); let signingkey = "key-123456"; let expireseconds = 3600; let connectstr = "redis://localhost"; chain.around(session::Session::new(signingkey, expireseconds, connect_str)); Iron::new(chain).http("localhost:3000").unwrap(); }
fn requesthandler(req: &mut Request) -> IronResult
req.set_session("address", "where are you?".to_owned()).unwrap();
let address = req.get_session::<String>("address").unwrap();
req.clear_session().unwrap();
let account_after_clear = req.get_session::<Account>("account");
let content = format!("account_session:{:?}\naddress:{}\naccount_after_clear:{:?}",
account_session,
address,
account_after_clear);
Ok(Response::with((iron::status::Ok, content)))
}
```
If you're using cargo, just add router to your Cargo.toml
.
```toml [dependencies]
session = "*" ```
Otherwise, cargo build
, and the rlib will be in your target
directory.