Nest.js API endpoint for validating the POST data

1.2k views Asked by At

I want to validate the entity data separately from making a POST request and display errors in the form. I'm using class-transformer. What's the best way to achieve this with Nest?

1

There are 1 answers

4
Jay McDoniel On

Sounds exactly like what the ValidationPipe is for. You decorate your DTO with class-validator decorators, set the @Body() type in your endpoint, and bind the pipe and viola, the request gets validated when sent to the server and returns errors that you can parse if any exist