1.0.4 • Published 4 years ago

koa-captor v1.0.4

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

npm version

koa-captor

Installation

npm install --save koa-captor

Usage

const Koa = require('koa')
const Joi = require('@hapi/joi')
const Router = require('koa-router')
const captor = require('koa-captor')

const app = new Koa()
const router = new Router()

const middleware1 = async (ctx, next) => {
  console.log('middleware 1')
  await next()
}

const middleware2 = async (ctx, next) => {
  console.log('middleware 2')
  await next()
}

router.get('/:name', captor({
  validations: {
    // or params or query or files or file
    body: Joi.object({
      name: Joi.string().required()
    })
  },
  middlewares: [
    middleware1,
    middleware2
  ],
  handler: ({ request, response }) => {
    return response.code(201).json({ hello: "world" })
  }
}))

Other ways to use the handler method:

handler: ({ request, response }) => {
  return { hello: "world" }
}
handler: ({ request, response }) => {
  return response.json({ hello: "world" })
}
handler: ({ request, response }) => {
  return response.code(404)
}

Author

Gideão Silva

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.13

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago