Express-inspired, rapid, scalable, concurrent and safe server development
#[deriving(Clone)]
pub struct ResponseTime { entry: u64 }
impl ResponseTime { fn new() -> ResponseTime { ResponseTime { entry: 0u64 } } }
// This Trait defines middleware.
impl MiddleWare for ResponseTime {
fn enter(&mut self, _: &mut Request, _: &mut Response, _: &mut Alloy) -> Status {
self.entry = precise_time_ns();
Continue // Continue to other middleware in the stack
}
fn exit(&mut self, _: &mut Request, _: &mut Response, _: &mut Alloy) -> Status {
let delta = precise_time_ns() - self.entry;
println!("Request took {} ms.", (delta as f64) / 100000.0)
Continue
}
}
// ...
server.chain.link(ResponseTime::new());
// ...
Iron is a high level web framework built in and for Rust.
Iron does not come bundled with any middleware - instead, Iron is a robust and efficient framework for plugging in middleware.
Iron focuses on providing a clean API for creating middleware and integrating them in Iron servers.
After spawning, handling a single request through Iron’s middleware stack with a single no-op middleware takes only 0.9 micro seconds - with ten middleware, it's only 1.1 microseconds.
Iron averages 2500-3000+ requests per second for hello world, up to 600 more than Express and 1000 more than Koa.
Iron aims to fill a void in the Rust web stack - a high level framework that is extensible and makes organizing complex server code easy.
Middleware is painless to build, and the core bundle already includes:
- Routing
- Mounting
- Static file-serving
- Body parsing
- Url encoding
- Logging
- Cookies
- Sessions
- Persistent storage
This allows for insanely flexible and powerful setups and allows nearly all
of Iron’s features to be swappable - you can even change the middleware
resolution algorithm by swapping in your own Chain
.
If you're using Cargo
, just add Iron to your Cargo.toml
:
[dependencies.iron]
git = "https://github.com/iron/iron.git"
Otherwise, just clone this repo, 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
.
impl Middleware
to create your own, or pass a function with the correct signature to FromFn::new
.
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
.