NestJS — Validate requests with custom decorators

Liu Ting Chun
5 min readDec 18, 2019

It is a must to add validation to all your APIs to avoid unexpected usage. The official document of NestJS suggests to validate requests with the Validation Pipe. Yet, the drawback is you will have to create a DTO for each API. If you don’t like the official approach, you may try my custom decorator approach. Imagine something like this:

@Post('create-proposal')
@Validate()…

--

--

Liu Ting Chun

Web developer from Hong Kong. Most interested in Angular and Vue. Currently working on a Nuxt.js + NestJS project.