lambda-validator
v1.0.7
Published
Parses and validates Lambda POST bodies with class-validator
Downloads
1
Maintainers
Readme
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[]