evantahler/actionHero — pull request #137 by evantahler (2013-03-28 03:56:49+00:00)
Title: Routes

- **upgrades the routes sub-system to be more like rails/express**
- **closes https://github.com/evantahler/actionHero/issues/104**

From Versions.md:

For web clients (http and https) you can define an optional RESTful mapping to help route requests to actions.
If the client doesn't specify and action in a param, and the base route isn't a named action, the action will attempt to be discerned from this routes.js file.

- routes remain optional
- actions defiend in params directly `action=theAction` or hitting the named URL for an action `/api/theAction` will always override RESTful routing
- you can mix explicitly defined params with route-defined params. If there is an overlap, the route-defined params win
- IE: /api/user/123?userId=456 => `connection.userId = 123`
- this is a change from previous versions
- routes defined with the "all" method will be duplicated to "get", "put", "post", and "delete"
- use ":variable" to defined "variable"
- undefined ":variable" will match
- IE: "/api/user/" WILL match "/api/user/:userId"
- routes are matched as defined here top-down

example:
```javascript
{
get: [
{ path: "/users", action: "usersList" }, // (GET) /api/users
{ path: "/search/:term/limit/:limit/offset/:offset", action: "search" }, // (GET) /api/search/car/limit/10/offset/100
],

post: [
{ path: "/login/:userID", action: "login" } // (POST) /api/login/123
],

all: [
{ path: "/user/:userID", action: "user" } // (*) / /api/user/123
]
}
```