Koa.js support for Node.js


Introduction

Koa.jsexternal link is a web framework, which aims to be a smaller, more expressive, and more robust foundation for web applications and APIs.

Objects

This extension, when Koa.js library is found in the source code, may create the following objects:

Icon Description
NodeJS Get Operation
NodeJS Post Operation
NodeJS Put Operation
NodeJS Delete Operation
NodeJS Patch Operation
NodeJS Use Operation

Example

Example Webservice application from Koa:

var koa = require('koa'),
  router = require('koa-router'),
  cors = require('koa-cors'),
  json = require('koa-json'),
  errorHandler = require('koa-onerror'),
  bodyParser = require('koa-body')(),
  app = koa(),
  routes = new router();

function render(controller, action) {
}

/* routes start */
routes.get(  '/todos',                     render('todos',     'all'));
routes.post( '/todos',        bodyParser,  render('todos',     'create'));
routes.get(  '/todos/:id',                 render('todos',     'show'));
routes.del(  '/todos/:id',                 render('todos',     'delete'));
routes.patch('/todos/:id',    bodyParser,  render('todos',     'update'));
routes.del(  '/todos',                     render('todos',     'deleteAll'));

app.use(require('./app/middlewares/request_logger')());
app.use(json());
app.use(cors({methods: ['GET', 'PUT', 'POST', 'PATCH', 'DELETE']}));
app.use(routes.middleware());

errorHandler(app);

app.listen(Number(process.env.PORT || 9000));

The code above will create the links and objects below: