New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

koaw

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koaw

Create APIs using Koa and Waterline

  • 0.4.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
increased by133.33%
Maintainers
1
Weekly downloads
 
Created
Source

Koaw Build Status

Create APIs using Koa and Waterline. Koaw creates auto-generated CRUD routes, using the co approach and the middleware design pattern.

Install

With npm do:

$ npm install koaw --save

Usage

const Koa = require('koa')
const Koaw = require('koaw')
const Waterline = require('waterline')
const Stores = require('./collections/stores')

// Set collections to ORM
let waterline = new Waterline()
waterline.loadCollection(Stores)

// Create server
let server = new Koa()

// Set new controller
let controller = new Koaw({
  orm: waterline,
  model: 'store'
})

controller
  // Set methods to be used
  .methods('get post put delete')
  // Add middlewares to extend logic using generators
  .before('post', function *(next) { /* some logic */ yield next })
  .after('post', function *(next) { /* some logic */ yield next })
  .before('post put', function *(next) { /* some logic */ yield next })
  .after('post put', function *(next) { /* some logic */ yield next })
  .after('put', function *(next) { /* some logic */ yield next })
  // Register controller
  .register(server)

waterline.initialize({}, function (err) {
  server.listen(4000)
})

The above code registers the following routes:

POST /stores
GET /stores
GET /stores/:id
PUT /stores/:id
DELETE /stores/:id

API

.methods(methods)

Change default methods with an array or whitelisted string. These are default methods: post put get delete.

.override(methods, handler)

Change default handler of auto-generated routes. The methods should be specified with an array or whitelisted string.

.route(methods, path, fn)

Add custom route to given model. The methods should be specified with an array or whitelisted string. For instance, .route('get', 'custom', fn) should generate this route: GET /[collection]/custom

.before(methods[, path], fn)

Add a before middleware to one or more methods, both custom routes and auto-generated routes. The methods should be specified with an array or whitelisted string.

.after(methods[, path], fn)

Add an after middleware to one or more methods, both custom routes and auto-generated routes. The methods should be specified with an array or whitelisted string.

.register(server)

Register controller routes to server. .register must be called at the end of above methods.

Contribute

Todos

  • Add support to queries, filters and populating
  • Add support to subcontrollers to create nested routes

License

MIT

Keywords

FAQs

Package last updated on 17 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc