'Nest.js API endpoint for validating the POST data

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?



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jay McDoniel