1.0.0 • Published 5 years ago

beanify-schema-status v1.0.0

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

beanify-schema-status

beanify验证和序列化以及响应数据包封装

JavaScript Style Guide

install

npm i beanify-schema-status

usage

const Beanify = require("beanify")
const beanifyPlugin = require("beanify-plugin")

const beanify = new Beanify({})
beanify.register(require("beanify-schema-status")).register(beanifyPlugin((beanify, opts, done) => {
  beanify.addSchema({
    $id: 'myRequestSchema',
    type: 'object',
    properties: {
      a: { type: 'number' },
      b: { type: 'number', default: 10 }
    }
  })
  beanify.route({
    url: 'math.add',
    schema: {
      body: 'myRequestSchema#',
      response: {
        type: 'number'
      }
    }
  }, function ({ body }, res) {
    res(null, body.a + body.b)
  })
  done()
})).ready((err) => {
  beanify.inject({
    url: 'math.add',
    body: {
      a: 1,
    }
  }, function (err, res) {
    console.log(res == 11)
    beanify.close()
  })
})