mycro-mongoose-rest
v0.1.1
Published
mycro hook for implementing restify-mongoose
Downloads
2
Maintainers
Readme
mycro-mongoose-rest
a restify-mongoose hook for mycro
NOTE This is still very much a work in progress and is not yet suitable for use in production
Install
npm install --save mycro-mongoose-rest
General Usage
- Define a config file at
/config/restify-mongoose.js
- Define a
defaults
attribute that defines the default options forrestify-mongoose
- Define a
models
attribute with a key for every model that you intend to create arestify-mongoose
resource for.
// in /config/restify-mongoose.js
module.exports = {
// define default options for all models
defaults: {
pageSize: 20,
baseUrl: 'https://www.example.com/api'
}
models: {
// use defaults for `group` model
group: true,
// define additional options for `user` model
user: {
// define options that will be applied to all Resource methods
defaults: {
detailProjection: function(req, item, cb) {
cb(null, item.toObject());
},
filter: function(req, res) {
return { status: 'active' };
},
listProjection: function(req, item, cb) {
cb(null, item.toObject());
}
},
// define options that will be applied to the `query` method
query: {
sort: '-first'
}
}
}
}
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
License
Copyright (c) 2015 Chris Ludden. Licensed under the MIT license.