npm.io
1.0.7 • Published 7 years ago

lambda-validator

Licence
MIT
Version
1.0.7
Deps
1
Size
9 kB
Vulns
1
Weekly
0

Pretty straightforward to run!

Installation

  • yarn add lambda-validator
  • yarn add class-transformer

Usage

import { Length } from 'class-validator'

// Create a class for the body and decorate it
class Body {
  @Length(5,20) name: string
}

// Example request usage
export const hello: APIGatewayProxyHandler = async (event, _context) => {
	const body = await ValidateBody(Body, event.body)

	return {
		statusCode: 200,
		body: JSON.stringify(body),
	}
}

API

Default function:

ValidateBody<Class>(targetType: Class, bodyString?: string | null, opts?: ValidatorOptions) => Promise<Class> Rejects with ValidationError[]

Keywords