A resource-oriented DSL for configuring koa.
To configure resourced you need to tell it which directory to look for resources in:
varresourced=require('resourced');varrouter=require('koa-router');Q.spawn(function*(){// ...app.use(router(app));varresourcesDir=__dirname+'/resources';yield*resourced.configureResourcesInDirectory(resourcesDir,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:
varResource=require('resourced').Resource;varhttp=require('resourced').http;varcache=require('resourced').cache;varensure=require('rules').ensure;varaddressResource=require('./address');varpeople=[{firstName: "bob",lastName: "smith",id : 1,"job": "tinker",addressId: 3}];module.exports=newResource({url: "/person/:id",cache: cache.minutes(5).publically(),respondsTo: [http.get(function*(id){ensure(id).populated().numeric({min : 0});varperson=people[id];person.address=this.urlFor(addressResource,{id: person.addressId});returnperson;})]});You can run the sample application using the following command:
node --harmony examples\web.js
##Features
- Request Handlers - Features like argument population make handling requests easier.
- Caching - HTTP caching of responses to GET requests.
- Validation - Allows validation of request bodies and URL's.
