Skip to content
forked from iron/persistent

Middleware for sharing data between requests

Notifications You must be signed in to change notification settings

darayus/persistent

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

99 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

persistent Build Status

Persistent storage as middleware for the Iron web framework.

Example

use iron::Plugin; // Request::get is provided through this trait.

pub struct HitCounter;
impl Assoc<uint> for HitCounter {}

fn serve_hits(req: &mut Request) -> IronResult<Response> {
    let mutex = req.get::<Write<HitCounter, uint>>().unwrap();
    let mut count = mutex.lock();

    *count += 1;
    Ok(Response::with(status::Ok, format!("Hits: {}", *count)))
}

fn main() {
    let mut chain = ChainBuilder::new(serve_hits);
    chain.link(Write::<HitCounter, uint>::both(0u));
    Iron::new(chain).listen(Ipv4Addr(127, 0, 0, 1), 3000);
}

Overview

persistent is a part of Iron's core bundle.

  • Share persistent data across requests
  • Read or modify locally stored data

Installation

If you're using a Cargo.toml to manage dependencies, just add persistent to the toml:

[dependencies.persistent]

git = "https://github.com/iron/persistent.git"

Otherwise, cargo build, and the rlib will be in your target directory.

Along with the online documentation, you can build a local copy with make doc.

Get Help

One of us (@reem, @zzmp, @theptrk, @mcreinhard) is usually on #iron on the mozilla irc. Come say hi and ask any questions you might have. We are also usually on #rust and #rust-webdev.

About

Middleware for sharing data between requests

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%