开发者社区> 镜像站> NPM> @palmabit/lambda-joi-validator
@palmabit/lambda-joi-validator
## Install
Last updated a year ago by eliardo .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @palmabit/lambda-joi-validator 
SYNC missed versions from official npm registry.

Lambda Joi Validator

Install

npm install @hapi/joi
npm install @palmabit/lambda-joi-validator

Usage

const Joi = require('@hapi/joi')
const LambdaJoiValidator = require('@palmabit/lambda-joi-validator')
const schema = {
  query: Joi.object().keys({
    foo: Joi.string()
  })
}
const validator = new LambdaJoiValidator(schema)

module.exports.handler = (event, context, callback) => {
  validator.validate(event)
    .then(value => {
      callback(null, {
        statusCode: 200,
        body: 'Valid!!!'
      })
    })
    .catch(error => {
      callback(null, {
        statusCode: 400,
        body: error
      })
    })
  }

Schema

You can define query, body and/or headers schemas validator:

const schema = {
  query: Joi.object().keys({
    foo: Joi.string()
  }),
  body: Joi.object().keys({
    bar: Joi.number()
  }),
  headers: Joi.object().keys({
    foobar: Joi.string()
  })
}

Current Tags

  • 1.2.1                                ...           latest (a year ago)

8 Versions

  • 1.2.1                                ...           a year ago
  • 1.2.0                                ...           a year ago
  • 1.1.3                                ...           a year ago
  • 1.1.2                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Downloads
Today 0
This Week 1
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (1)
Dependents (0)
None