nickel-org/nickel.rs — pull request #108 by SimonPersson (2014-11-01 00:02:00+00:00)
Title: feat(nickel): Support for sharing data between requests per route basis.

My attempt at issue #79.

This is mostly non breaking. As far as I know, nothing will break unless people were implementing `RequestHandler` for something else than the default implementation. I don't think anyone did though.

The new feature is that it is possible use a handler signature like `fn root_handler (_request: &Request, response: &mut Response, route_data: &RouteData)`, and then register it with the router with `server.get_with_data("/", root_handler, RouteData{...});` as can be seen in the new example I've added.

This has many usecases, many of which required a middleware before. In the new example provided I count how many hits a route has gotten. One could also store a database connection in there, as is the example in issue #79 where this comes from.

I've been fighting the compiler with this for some time so some refactoring that I can't spot right now might be needed, point out anything you find! We might also want to discuss the naming of the new router methods (`get` - `get_with_data` and so on) and come up with something that feels good. =)