visionmedia/express — pull request #1905 by defunctzombie (2014-01-19 23:02:54+00:00)
Title: Make each route a separate middleware stack.

DO NOT MERGE THIS

This PR is only for code review and API change review and discussion.

This is the start of a number of larger changes that I hope to land for the 4.0 release. All of the changes will be surrounding routing. This particular changeset changes what a `Route` is. Previously, a Route would be defined by the path, method, and callbacks. Now a Route is only a path. This route can have middleware applied to it via (.use) and has all of the http verbs (.get, .post) etc. This makes all routes self contained middleware stacks. It also changes the behavior of the `Router.route` method call. Previously this took a method, path, and callbacks. Now it just takes a path and returns the created `Route` object allowing for the following API style:

```js
router.route('/foobar')
.use(fn...)
.use(fn...)
.get(fn..)
.post(fn...)
```

This likewise means that once I remove the `app.route` property from its currently hacky use for mounted apps, we will also be able to do the same on the `app` variables.

```js
app.route('/user')
.use()
.get()
.post()
```

Taking this one step further, I want to remove the dependency on connect as mentioned by @jonathanong so that we can have control over our routing stack allowing us to possibly throw on out of order app.use calls or somehow be smarter about it (not relevant to this current changeset).

A side effect of these changes (I did not intend for this) is that the benchmarks run faster (on my computer). This may have to do with the particular way the benchmark suite is setting up middleware or routes that just lends itself more favorably to this new route approach.

No tests have been adding for the new API as I am looking for general feelings on this change and landing the above described changes for 4.0.