Iron Selective Middleware
This crate allows you to selectively add middleware to specific handlers in an Iron application.
Motivation
I needed a way to add middleware to specific Iron routes. Using the Iron Router and Chain, it was only possible to add middleware to the entire Router as a whole. I created this crate to allow middleware to be added to any handler in the application.
The use case I had was authentication middleware. I needed to add this middleware to every route which required the user to be authenticated. I didn't want to add it to the login handler, though. SelectiveMiddleWare solves this problem for me.
Installation
Add the following to the [dependencies] section of you Cargo.toml:
= "*"
Usage
extern crate iron;
extern crate router;
extern crate selective_middleware;
use ;
use Router;
use SelectiveMiddleWare;
With the above example, visiting http://localhost:3000/ will invoke the
handler method. Visiting http://localhost:3000/foo will invoke MyMiddleware
then the handler method.
There is also the with_middleware! convenience macro:
extern crate selective_middleware;