3.0.15 • Published 3 years ago

beanify-ajv v3.0.15

Weekly downloads
92
License
MIT
Repository
github
Last release
3 years ago

beanify-ajv

Used to verify req.body, route.$attribute parameter structure and rep.$data return results

Install

npm i beanify-ajv --save

with yarn

yarn add beanify-ajv

Usage

const Beanify = require('beanify')
const Ajv = require('beanify-ajv')
const beanify = Beanify({})

beanify
  .register(Ajv, {
    ajv: {
      useDefaults: true
    }
  })
  .route({
    url: 'math.:action',
    schema: {
      body: {
        type: 'object',
        properties: {
          aaa: {
            type: 'string'
          }
        },
        required: ['aaa']
      },
      attribute: {
        type: 'object',
        properties: {
          bbb: { type: 'number' }
        }
      },
      response: {
        type: 'string'
      },
      params: {
        type: 'object',
        properties: {
          action: {
            type: 'string'
          }
        }
      }
    },
    handler (req, rep) {
      // const e = new Error('message test')
      // rep.error(e)
      console.log(req.params)
      rep.send(req.body)
    }
  })
  .ready(async e => {
    e && beanify.$log.error(e.message)
    beanify.print()
    beanify.inject({
      body: { aaa: 'abc' },
      attribute: { bbb: 12345 },
      url: 'math.add',
      handler (e, data) {
        console.log({ e, data })
      }
    })
  })

Options

  • ajv: used to configure AJV instance.check here

Route Decorators

  • schema:
    • params: to check req.params field.check here
    • body: to check req.body field.check here
    • attribute: to check route.$attribute field.check here
    • response: to check rep.$data field.check here
3.0.15

3 years ago

3.0.14

3 years ago

3.0.12

3 years ago

3.0.13

3 years ago

3.0.11

3 years ago

3.0.10

3 years ago

3.0.8

3 years ago

3.0.9

3 years ago

3.0.7

3 years ago

3.0.6

3 years ago

3.0.4

3 years ago

3.0.5

3 years ago

3.0.3

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

1.1.3

4 years ago

1.1.1

4 years ago

1.1.2

4 years ago

1.1.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago