nerm
RESTful API generator for Express and Mongoose. Nerm maps routes directly to your mongoose models.
Nerm came about because we needed a light weight API generator. Nerm's feature set is small but useful. If you need a more full featured generator, check out Express Restify Mongoose.
Installation
npm install nerm
Basic Usage
var Nerm = var mongoose = mongoose var Schema = name: String location: String var User = mongoose Nerm
GET /api/v0/users
POST /api/v0/users
GET /api/v0/users/ffffffffffffb00000000001
PUT /api/v0/users/ffffffffffffb00000000001
DELETE /api/v0/users/ffffffffffffb00000000001
Queries
Queries in GET requests are made by passing a mongo query as a JSON string. To make a Regexp query, use the $like operator.
var q = JSONrequest// Translates to {location: 'New York', name: /john/i}
Sort Select and Populate
GET requests can also be given sort, select, and populate options.
request// Will return objects without location info and sorted by name in descending order
Middleware
Middleware can be provided in order to restrict access to routes
//This will restrict access to a individual user unless that user makes the request Nermapp
Private Fields
Schemas can be decorated with a private option.
var Schema = name: String location: type: String nerm: private: true var User = mongoose Nerm// This will not allow nonadmins to filter or modify location,// and will not return location fields in the responses.
Readonly Fields
Schemas can be decorated with a readOnly option.
var Schema = name: String location: type: String nerm: readOnly: true var User = mongoose Nerm// This will allow location to be filtered, but not modified by nonadmins
Scope
Sometimes a resource needs to be further restricted. To do that pass a scope function or literal. The function can be syncronous or asyncronous.
Nerm Nerm Nerm// Callers will only be able to retrieve other users in their location.
Defaults
Default options can be provided by calling Nerm.defaults, these will apply to all routes not given their own options
Nerm Nerm //No callers will have access to private fields now