1.1.0 • Published 10 months ago

@tadashi/koa-router v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

koa-router

NPM version Node.js CI Coverage Status

The simple and tiny route middleware for koa.

Install

$ npm i @tadashi/koa-router

Usage

Contrived example:

import Koa from 'koa'
import router from '@tadashi/koa-router'

const fakeAuth = (ctx, next) => {
  ctx.state.auth = true
  return next()
}

const productMiddleware = ctx => {
  ctx.body = {
    auth: ctx.state.auth,
    id: ctx.params.id
  }
}

const app = new Koa()
app
  .use(router.get('/product/:id', fakeAuth, productMiddleware))
  .use(router.all('/', ctx => {
    ctx.body = 'nothing to see here!'
  }))

//...

!TIP
It's possible to use koa-compose to group routes.
See an example in router.spec.js.


!IMPORTANT
Buy me a coffee!
BTC: bc1q7famhuj5f25n6qvlm3sssnymk2qpxrfwpyq7g4

License

MIT © Thiago Lagden

1.1.0

10 months ago

1.0.0

10 months ago