Skip to content

areusjs/http-resource

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Areus HTTP Resource Creator

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published