1.2.1 • Published 5 years ago

@palmabit/lambda-joi-validator v1.2.1

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

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()
  })
}
1.2.1

5 years ago

1.2.0

5 years ago

1.1.3

5 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago