era
REST adapter for express.
- Current version: 0.0.3
Important
- Package under heavy modifications.
- Authentication was disabled from version > 0.0.2.
- Default behavior
Installation
$ npm install -g era
About
This package is intended for fast development of REST APIs.
Quick start
var era = ; var Api = eraApi;var Authentication = eraAuthentication;var ModelResource = eraModelResource;
Declare a new resource
{ ModelResource;}util;
and a new api
var api = 'api' 'v1';
and register your new resource:
api;
Now, for this resource you have working CRUD functionality and the urls /api/v1/user
and /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 get
, post
, put
and delete
methods.
Routing with express
The api object is the one we built before.
var express = ;var app = ; app;app;app;app; api;
Authentication
Authentication
have no rules so you'll have to extend it and implement isAuthenticated
for setting your own rules.
Here is an example:
{ Authentication;};util;ApiKeyAuthprototype { var apikey = reqqueryapikey; if apikey modelsUser; else res; }
Model
The default CRUD behavior of the resource is built on top of mongoose. If you use
something else you have to implement get
, post
, put
and delete
methods of your resource, so mongoose
driver is not a requirement.
Working with express
Everything you'll extend with era is a middleware for express.
License
MIT