On Sat, Jun 2, 2012 at 8:13 AM, Gustavo Machado <[email protected]> wrote:
> In our team, we use the pattern Glenn Block described, and it's a very cool
> way of organizing your routes. What we do, is add a "hook" method in each
> resource, and we pass the "app" object so that every resource gets to define
> it's own endpoints. The only problem I've seen so far, is that you don't
> have all the routes in one place, so I think that something like this could
> help "isolate" routes:

It seems like this limits your flexibility in ordering the routes. Not
drastically, perhaps, but suppose I would write the following using
Glenn Scott's / TJ's style:

app.get(route1, handler1);
app.get(route2, handler2);
app.get(route3, handler1);

Assume that the order of the routes is important, and note that the
same handler is used for the 1st and 3rd routes. How would I write
this in the self-registering model you describe?

--
Martin Cooper


> https://github.com/visionmedia/express/pull/1156
>
> Not such a big deal though.
>
> Cheers!
> Gustavo
>
>
> On Thu, May 31, 2012 at 1:34 PM, tjholowaychuk <[email protected]>
> wrote:
>>
>> the pattern you're describing is what I prefer to do with express apps
>> as well.
>> some people like the "convention over configuration" sort of API
>> better, aka
>> something more like express-resource, but personally I find a simple
>> list of
>> routes is by far the easiest to scan over. Plus writing app.get('/
>> dogs', dogs.index)
>> vs exports.index = function(){} and having the framework automatically
>> know
>> what to do with this method really doesn't save that much time if any
>> since
>> you're introducing more obscurity
>>
>> On May 31, 8:55 am, Glenn Scott <[email protected]> wrote:
>> > I want to build out an API using restify.    I'd like to lay out the
>> > project logically so it doesn't become a mess as it grows, but I also
>> > don't want to get precious about it.  I'm looking for advice.
>> >
>> > I was thinking that in the main module ("api.js" ) I would put all the
>> > routes for every resource; and for the callbacks in each route I would
>> > put the name of a handler that I export from a module that corresponds
>> > to the resource, e.g., given a resource "dogs":
>> >
>> > api.js:
>> > --------
>> >
>> >    var apiDogs = require( './lib/dogs.js');
>> >    server.get('/dogs', apiDogs.dogHandler );
>> >
>> > dogs.js
>> > ----------
>> >
>> >    exports.dogHandler = function(req, res, next ) {
>> >       // do lots of stuff here
>> >       return next();
>> >    });
>> >
>> > Is this the right pattern?  Is there a better one?   Should I just put
>> > everything into api.js and calm down?
>>
>> --
>> Job Board: http://jobs.nodejs.org/
>> Posting guidelines:
>> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
>> You received this message because you are subscribed to the Google
>> Groups "nodejs" group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/nodejs?hl=en?hl=en
>
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to