0.1.1 • Published 9 years ago

koa-resource-builder v0.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

koa-resource-builder

Status: Alpha

Fluent DSL for building RESTful resources using Koa

Install

npm i -D koa-resource-builder

Usage

import ResourceBuilder from 'koa-resource-builder'
import koa from 'koa'
import Project from './models/project'
import ProjectDecorator from './decorators/project'

let resource = ResourceBuilder
    .init('tasks')
    .action('update')
        .use(authenticate)
        .use(function* fetchEntity() {
            this.model = Project.forge({ id: this.params.project })
            yield this.model.fetch({ require: true })
        })
        .use(function* decorateEntity() {
            this.entity = new ProjectDecorator(this.model)
            yield this.entity.decorate()
        })
        .use(function* respond() {
            this.body = this.entity.toJSON()
        })
        .end()
    .action('show')
        .use(function* () {
            ...
        })
        .end()
    .end()

app.use(resource.middleware());

License

MIT © lorefnon