1.0.0-alpha.0 • Published 4 years ago

@sstack/validate v1.0.0-alpha.0

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

@sstack/validate

Request & response schema validation using ajv.

npm i @sstack/validate --save

Usage

You'll want to use this library in conjunction with @sstack/json, since @sstack/validate assumes the body will be parsed and stringified.

const { sstack, main } = require('sstack')
const { parse, stringify } = require('@sstack/json')
const validate = require('@sstack/validate')

exports.handler = sstack([
  parse(),
  validate.request({
    type: 'object',
    properties: {
      email: {
        type: 'string'
      },
      password: {
        type: 'string'
      }
    },
    required: [
      'email',
      'password'
    ]
  }),
  main(event => {
    const { email, password } = event.body
    const user = logIn(email, password)

    return {
      body: {
        name: user.name
      }
    }
  }),
  validate.response({
    type: 'object',
    properties: {
      user: {
        type: 'object',
        properties: {
          name: {
            type: 'string'
          }
        }
      }
    }
  }),
  stringify()
])

License

MIT License © Eric Bailey

1.0.0-alpha.0

4 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.0

5 years ago

0.0.4

5 years ago

0.0.1

5 years ago