scalatra/scalatra — Issue #145: Route metadata
Author: rossabaker
Created: 2011-12-17 07:36:32+00:00
State: open
Labels: ideas

We've had a couple needs lately for metadata on routes:

* @robb1e is working on [self-documenting routes](https://github.com/robb1e/scalatra)

* @casualjim wants a way to configure timeouts per route with the new async support

The challenge is to make it flexible enough that these, and future extensions, can coexist without breaking the simple Sinatra feel of our DSL.

One possible solution:
1) Add a `metadata: Map[Symbol, Any]` to Route
2) Define a RouteTransformer as Route => Route
3) Signature in ScalatraKernel becomes `get(RouteTransformer*)(=> Any)`
4) Create a default route from the Action: no matchers, no metadata
5) Compose the RouteTransformers and apply to the route from the previous step

RouteTransformers might:
1) Add a route matcher
2) Decorate the action
3) Register metadata
4) Any combination of the above.

Implicits would still exist to convert String, Boolean, and Pattern to RouteTransformers, so the basic DSL is unchanged.

Another idea on the table is to add "as" and "and" keywords to make it literate.

get("/foo" as Async) { somethingSlow() }