areus-http-resource

    0.1.1 • Public • Published

    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

    Install

    npm i areus-http-resource

    DownloadsWeekly Downloads

    1

    Version

    0.1.1

    License

    MIT

    Last publish

    Collaborators

    • ddrinf
    • nemtsov