kieran / barista

A URL router / generator for NodeJS
https://kieran.github.io/barista/
MIT License
111 stars 22 forks source link

Customizing Resources #24

Open jorr opened 10 years ago

jorr commented 10 years ago

A slightly exotic but I believe useful option, would be letting resources:

The case these try to solve is pretty URLs for categories of a single resource. Say in a shop website, having /chairs/:id, /tables/:id, /beds/:id all dispatch to a Product controller with a type parameter to distinguish between them.

I imagine something in the lines of:

router.resource(':type','Products')

which would be pretty easy to implement - just provide the first parameter instead of #{slug} and the second parameter instead of #{controller} in the routes generated by the constructor. The methods of the controller would then have params.type available as whatever was between the slashes.

there might be a better syntax to make these optional and whatnot..