REST adapter for express
REST adapter for express.
- Current version: 0.0.3
- Package under heavy modifications.
- Authentication was disabled from version > 0.0.2.
- Default behavior
$ npm install -g era
This package is intended for fast development of REST APIs.
var era = require'era';var Api = eraApi;var Authentication = eraAuthentication;var ModelResource = eraModelResource;
Declare a new resource
ModelResourcecallthis model authentication;utilinheritsUserResource ModelResource;
and a new api
var api = 'api' 'v1';
and register your new resource:
Now, for this resource you have working CRUD functionality and the urls
/api/v1/user/:id are auto generated. The urls are base on the resource name, so the name has two parts, the model name, in our case is
User and the word
Resource, which is a mandatory word.
If you want to change behavior of the resource you have to override
The api object is the one we built before.
var express = require'express';var app = express;appuseexpresslogger;appuseexpresscompress;appuseexpressbodyParser;appuseapprouter;apiadapterapp;
Authentication have no rules so you'll have to extend it and implement
isAuthenticated for setting your own rules.
Here is an example:
Authenticationcallthis;;utilinheritsApiKeyAuth Authentication;var apikey = reqqueryapikey;if apikeymodelsUserfindOne'apikey': apikeyexecif objnext;elseressend401;;elseressend401;
The default CRUD behavior of the resource is built on top of mongoose. If you use
something else you have to implement
delete methods of your resource, so mongoose
driver is not a requirement.