trailsjs / doc

:books: Trails.js Documentation
Other
18 stars 10 forks source link

Extended routing functionality #21

Closed elimence closed 8 years ago

elimence commented 8 years ago

Currently, route definitions look as follows:

{
    method: [ 'GET' ],
    path: '/api/v1/default/info',
    handler: 'DefaultController.info'
}

Which is a it cumbersome, especially if you need to define lots of routes. Would be nice to be able to have a more succinct syntax, perhaps something like so?

Router
   .post( '/user', UserCtl.create)
   .put( '/user',   auth.isAuthenticated(), UserCtl.update)

Just an example, but you get my point I hope.

Also nested routes would be really nice, mostly for convenience, so stuff like this can be done:

{
    method: [ 'GET' ],                         // this here would/could be optional
    path: '/api/v1/default',
    handler: 'DefaultController.info'  // so would this guy

    subRoutes: [{
         method: [ 'GET' ],
         path: '/info',   // this then becomes /api/v1/default
         handler: 'DefaultController.info'
     }]
}

Also just an example, but I hope the general idea comes through. That should be all, I'll add updates if anything else comes to mind :)

jaumard commented 8 years ago

This has nothing to do with docs ^^ it's a feature request, can you move the issue to trails repo please ? Also having a Router object is not possible, or more something like:

Router
   .post( '/user', 'UserCtl.create')
   .put( '/user',   'auth.isAuthenticated', 'UserCtl.update')

Because middleware are in classes and need to be instantiate, Trails do it during launch process so you can't call them before.

Also this notation give less configuration possibilities:

At the end this notation is more complicated... I'll rather use the current notation :) but I'm 100% for the subrouting feature ! I'm closing this one please open a new one into trails repo and reference this issue for history. Thanks!