0.0.2 • Published 5 years ago

glisten v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

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');