JSPM

rest-tree

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q20877F

hierarchical RESTful routes utility

Package Exports

  • rest-tree

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (rest-tree) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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 ]