glisten
v0.0.2
Published
An opinionted framework for building JSON APIs with Postgres.
Downloads
1
Readme
glisten
An opinionated framework for building REST APIs with Postgres. Built on top of Koa and Objection.
Concepts
The main resources in glisten are Controllers and Models.
Controllers
Controllers the route handlers for your API. glisten automatically generates and mounts the routes onto Koa based on how you configure your Controller.
Default Controller Example
const { BaseController } = require('glisten');
class UsersController extends BaseController {
// POST /
create() {
return async ctx => {};
}
// GET /
list() {
return async ctx => {};
}
// GET /:id
get() {
return async ctx => {};
}
// PUT /:id
update() {
return async ctx => {};
}
// PATCH /:id
edit() {
return async ctx => {};
}
// DELETE /:id
delete() {
return async ctx => {};
}
}
module.exports = UsersController;
Simply return a standard Koa router handler and glisten will mount it.
Configure the Controller's Path
You can set this.prefix
in a Controller's constructor
to configure where the routes get mounted.
class UsersController extends BaseController {
constructor(options) {
super(options);
this.prefix = '/users';
}
// POST /users
// GET /users
// GET /users/:id
// ...
}
Mounting Controllers
glisten looks for Controllers in the src/controllers/index.js
file. Anything you export from that file must extend BaseController
and will be automatically mounted.
// src/controllers/index.js
exports.UsersController = require('./users-controller');