Skip to content

Instantly share code, notes, and snippets.

@nim23
Created May 30, 2015 19:17
Show Gist options
  • Save nim23/4bedb57965a663dd0c79 to your computer and use it in GitHub Desktop.
Save nim23/4bedb57965a663dd0c79 to your computer and use it in GitHub Desktop.
Book shelf koa
'use strict';
const router = require('koa-router')();
const Projects = require('../collection/projects'); //Bookshelf collection/model
router
.get('/projects', function *() {
this.body = yield Projects.forge().fetch();
})
.post('/projects', function *() {
const project = this.request.body;
try {
this.body = yield Projects.forge(project).save();
this.status = 200;
} catch (err) {
this.body = err;
this.status = 500;
this.throw(500, err);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment