Skip to content

BoostIO/tachijs-validated-body

Repository files navigation

TachiJS validated body

Build Status codecov NPM download Supported by BoostIO

Validate body with class validator!

How to use

Install peer dependencies.

npm i reflect-metadata class-validator class-transformer-validator class-transformer

Replace @reqBody() with @validatedBody().

import { validatedBody } from 'tachijs-validated-body'

class MessageRequestBodyDTO {
  @IsString()
  message: string
}

@controller('/')
class EchoController {
  @httpPost('/')
  // echo(@reqBody() body: unknown) {
  echo(@validatedBody() body: MessageRequestBodyDTO) {
    return body.message
  }
}

License

MIT © Junyoung Choi