9 releases
Uses old Rust 2015
0.1.8 | Aug 28, 2016 |
---|---|
0.1.7 | Aug 6, 2016 |
0.1.6 | Jul 28, 2016 |
#28 in #signing-key
10KB
192 lines
session
Request session extension for the Iron web framework.
session is a fast, convenient, and flexible extension for Iron Request. Use redis as the backend data repos.
Example
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"
fn main() {
let mut chain = Chain::new(handler);
let signing_key = "key-123456";
let expire_seconds = 3600;
let connect_str = "redis://localhost";
chain.around(session::Session::new(signing_key, expire_seconds, connect_str));
Iron::new(chain).http("localhost:3000").unwrap();
}
fn handler(req: &mut Request) -> IronResult<Response> {
let mut count = req.get_session::<usize>("count").unwrap_or(0);
count += 1;
req.set_session("count", &count).unwrap();
Ok(Response::with((iron::status::Ok, format!("count:{}", &count))))
}
Installation
If you're using cargo, just add session to your Cargo.toml
.
[dependencies]
session = "*"
Otherwise, cargo build
, and the rlib will be in your target
directory.
Examples
Dependencies
~7MB
~160K SLoC