visionmedia / express-resource

Resourceful routing for Express
1.41k stars 140 forks source link

customize generated urls #12

Closed ravinggenius closed 13 years ago

ravinggenius commented 13 years ago

Not sure how possible this would be, but... It would be super awesome if there was an option to customize the generated URLs on a per-action basis. For instance, assuming we only export new, create and destroy:

app.resource('sessions', require('./sessions'), { paths: { 'new': '/login' } });

... would generate URLs that would map to actions like this:

GET     /login              ->  new
POST    /sessions           ->  create
DELETE  /sessions/:id       ->  destroy

This would be especially cool if it played nice with bodyClasses (issue #11) in such a way that bodyClasses() for '/login' would generate 'sessions new'. This would be ideal.

pacovell commented 13 years ago

You can at least get the custom routes you want from:

var sessions = require('./sessions'); var sessionsResource = app.resource('sessions', sessions); sessionsResource.map('get', '/login', sessions.new);

I added test cases for these, you can see them in the current head. (Pull #25).

I see Issue #11 is closed, should we close this one as well?

ravinggenius commented 13 years ago

I cannot try it now, but that looks great, so thank you for the heads up. I'll go ahead and close this ticket.