Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/colin-jack/resourced
A resource-oriented DSL for configuring koa.
https://github.com/colin-jack/resourced
Last synced: 3 months ago
JSON representation
A resource-oriented DSL for configuring koa.
- Host: GitHub
- URL: https://github.com/colin-jack/resourced
- Owner: colin-jack
- Created: 2012-10-03T07:33:20.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-11-20T17:55:22.000Z (about 10 years ago)
- Last Synced: 2024-04-24T18:45:44.410Z (10 months ago)
- Language: JavaScript
- Homepage:
- Size: 891 KB
- Stars: 10
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-github-repos - colin-jack/resourced - A resource-oriented DSL for configuring koa. (JavaScript)
README
[![Build Status](https://travis-ci.org/colin-jack/resourced.png)](https://travis-ci.org/#!/colin-jack/resourced)
A resource-oriented DSL for configuring koa.
### Configuration
To configure resourced you need to tell it which directory to look for resources in:```js
var resourced = require('resourced');
var router = require('koa-router');Q.spawn(function *() {
// ...app.use(router(app));
var resourcesDir = __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.### Resource Definition
The following shows a simple person resource, where the JSON response includes a link to the associated address:
```js
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 }
];module.exports = new Resource({
url: "/person/:id",cache: cache.minutes(5).publically(),
respondsTo: [
http.get(function * (id) {
ensure(id).populated().numeric({ min : 0 });
var person = people[id];person.address = this.urlFor(addressResource, { id: person.addressId });
return person;
})
]
});
```## Running Examples
You can run the sample application using the following command:node --harmony examples\web.js
##Features
* [Request Handlers](https://github.com/colin-jack/resourced/blob/master/docs/requestHandling.md) - Features like argument population make handling requests easier.
* [Caching](https://github.com/colin-jack/resourced/blob/master/docs/caching.md) - HTTP caching of responses to GET requests.
* [Validation](https://github.com/colin-jack/resourced/blob/master/docs/validation.md) - Allows validation of request bodies and URL's.