0.1.3 • Published 10 years ago
nap-service v0.1.3
Nap
The highly-configurable RESTful HTTP service provider made for Express framework and Mongoose
Using it
var nap = require('nap');
api = nap(globalOptions);
api.add(modelObject);
api.inject(app);
globalOptions
authGroups
: an array containing all the different groups, ordered for a waterfall (last groups inherits the first group autorizations) (ex: `'guest')getRole
: a function called wth two arguments,userId
the id string, number or object corresponding to the current logged user andcallback
a function to be called with a string corresponding to the user rolecanThis
: overrides the canThis middleware. Injected athis
object:config
the passed configgetRole()
a Promise that wraps thegetRole
specified optiondeny()
call it to deny accessallow()
the accessurl
current urlparams
the request paramsmethod
the HTTP method
modelObject
model
the model name or objectauthorizations
an object where the value is the method (GET, PUT...) and the value an array of user roles (cascading). Example:get: ["guest"]
everybody, from guests to admins will be able to GETpost: ["user"]
only logged users or admins will be able to POSTput: ["admin"]
only admin will be able to do this
authorship
used when a user PUT his own mod he might be able to edit it even though he doesn't have the PUT authorization (see above). This is the name of the field that contains the author id.indexFields
the fields selected onGET /{model}
dontBreak
don't put the selected fields as a new model