node-restful icon indicating copy to clipboard operation
node-restful copied to clipboard

Override resource 'index' handler

Open flockonus opened this issue 12 years ago • 1 comments

Hey @baugarten, great work on this lib!

Is there a way to override the handler of specific endpoints on this object? For instance, for listing all of a certain resource i would like to show only a couple of fields and paginating

flockonus avatar Dec 17 '13 21:12 flockonus

Thanks! :)

Currently, there's no way to override the handler of specific endpoints. You can paginate the data manually using the parameters limit=?&skip=? You can limit the fields by either using an after route or modifying the mongoose schema to make paths not returnable by default.

i.e.

Resource.after('route', function(req, res, next) {
  res.locals.bundle = _.omit(res.locals.bundle, 'password', 'secret', 'etc');
  next();
});

baugarten avatar Dec 17 '13 21:12 baugarten