DEV Community

Cover image for Out-Of-The-Box DTO Validator
Richard Zampieri for ExpressoTS

Posted on

Out-Of-The-Box DTO Validator

👋 Hello Developers,

If you've been on the lookout for an out-of-the-box DTO Validator, your search ends here! ExpressoTS now offers a pre-integrated DTO Validator to make your life easier. 🎉

👉 Learn More

Here's how simple it is to use:

@httpPost("/", ValidateDTO(CreateUserDTO))
execute(@requestBody() payload: CreateUserDTO, @response() res: Response) {
  return res.status(StatusCode.Created).json(this.createUserUseCase.execute(payload));
Enter fullscreen mode Exit fullscreen mode

✨ Customization Flexibility

However, if our DTO Validator doesn't quite fit your unique needs, you're free to create your own provider! We've designed our system to be extensible, allowing you to plug in your own solutions.

Here's the signature you need to implement for your custom provider:

const yourprovider = (req: Request, res: Response, next: NextFunction) => { }
Enter fullscreen mode Exit fullscreen mode

Add it to the endpoint decorator and voila, you've replaced ValidateDTO with your own solution! 🛠️

For more information read the Official Documentation

ExpressoTS #DTOValidator #Customization #NodeJS #BackendDevelopment

Top comments (0)