rest-tree

hierarchical RESTful routes utility

npm install rest-tree
2 downloads in the last week
4 downloads in the last month

Rest Tree

So far the library simply allows to generate flattened RESTful routes from a tree-oriented description of end-points. The resulting routes can then be mounted into an HTTP server.

Install

npm install rest-tree

Usage

var rmount = require('rest-mount');
var rtree = require('rest-tree');

var routes = rtree.flatten({
  $enter: rbegin,
  contacts: {
    $enter: cstat,
    $post: cpost,
    _: {
      $node: ':contactId',
      $enter: [ uauth, cload, ccheck ],
      $put: [ cput, cdirty ],
      $get: cget,
      $del: cdel,
      emails: {
        $post: [ epost, cdirty ],
        $get: elist
      },
      $leave: csave,
    }
  },
  $leave: rend
});

rmount.mount(routes, http, '/service');

will produce these end-points

POST /contacts                   [ rbegin, cstat, cpost, rend ]
PUT  /contacts/:contactId        [ rbegin, cstat, uauth, cload, ccheck, cput, cdirty, csave, rend ]
GET  /contacts/:contactId        [ rbegin, cstat, uauth, cload, ccheck, cget, csave, rend ]
DEL  /contacts/:contactId        [ rbegin, cstat, uauth, cload, ccheck, cdel, csave, rend ]
POST /contacts/:contactId/emails [ rbegin, cstat, uauth, cload, ccheck, epost, cdirty, csave, rend ]
GET  /contacts/:contactId/emails [ rbegin, cstat, uauth, cload, ccheck, elist, csave, rend ]
npm loves you