NestJs: Why do we need DTOs and interfaces both in NestJS?

Answer

I think it's important to know what DTO is.

DTO(Data Transfer Object) is a concept of Java(J2EE) design.

It looks like a normal Java Bean object, which was created for transferring data object through multiple layers (such as controller, service, database) in our backend, especially in Distributed Systems.

With DTO Model:-

It helps us to handle our data object.

In the guide of NestJS, DTO acts like a HTTP Request body.

In my opinion, DTO contains:

some attributes we would use but not in Database.
and DTO masks:

some attributes we don't want to expose.
To use with class-validator, DTO can also help us validate data in an elegant way.

Sometimes it looks same with object interface.

I think DTO matters when our database collection is huge and complex.

All tailwind Questions

Ask your interview questions on tailwind

Write Your comment or Questions if you want the answers on tailwind from tailwind Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---