0.1.1 • Published 10 years ago

areus-http-resource v0.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

HTTP Resource Build Status NPM version

This is a helper library used to set-up routing in an areus-di express app.

Usage

server.js

var express = require('express'),
  di = require('areus-di')(__dirname),
  resource = require('areus-http-resource')(di, express.Router),
  app = express();

app.use('/api/users', resource('users'));
app.use('/api/articles', resource('articles'));

app.listen(3000);

resources/users.js

module.exports = UsersResource;

function UsersResource() {
}

UsersResource.prototype.route = function (router) {
  router.get('/', this.getAll.bind(this));
};

UsersResource.prototype.getAll = function (req, res, next) {
  res.json([
    {id: 1},
    {id: 2}
  ]);
};

route() is the only special method. It takes an express.Router as the first and only argument. Use it to delegate handling of different types of requests to the appropriate methods of the class.

License

MIT