Naboo's Podracing Misadventure
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    rest-treepublic

    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 ]
    

    Keywords

    none

    install

    npm i rest-tree

    Downloadslast 7 days

    0

    version

    0.1.0

    license

    none

    repository

    github.com

    last publish

    collaborators

    • avatar