A resource oriented DSL for configuring koa.
NOTE - This is a very early version of this project and is not yet fully featured.
A resource-oriented DSL for configuring koa.
To configure resourced you need to tell it which directory to look for resources in:
var resourced = require'resourced';var router = require'koa-router';Qspawn// ...appuserouterapp;var resourcesDir = __dirname + '/resources';yield * resourcedconfigureResourcesInDirectoryresourcesDir app;// ,,,;
Note that koa-router is also required and that it, and any other middleware, must be installed before resourced.
The following shows a simple person resource, where the JSON response includes a link to the associated address:
var Resource = require'resourced'Resource;var http = require'resourced'http;var cache = require'resourced'cache;var ensure = require'rules'ensure;var addressResource = require'./address';var people =firstName: "bob" lastName: "smith" id : 1 "job": "tinker" addressId: 3;moduleexports =url: "/person/:id"cache: cacheminutes5publicallyrespondsTo:httpgetensureidpopulatednumeric min : 0 ;var person = peopleid;personaddress = thisurlForaddressResource id: personaddressId ;return person;;
You can run the sample application using the following command:
node --harmony examples\web.js