Why do we use DTOs in our APIs?

Описание к видео Why do we use DTOs in our APIs?

Why do we use DTOs in our APIs? That's a question I have received often as comment to different videos om ASP.Net Core WebAPis. In this video we try to demystify the concept of DTOs and why do we use them? A short answer is that we don't want to expose full domain models in our API contracts, as those models usually contain a lot of information that is not needed to by the consumers of our different endpoints. But there's also a technical reason why DTOs are helpful, as we might get a lot of Json serialization exceptions if we don't use them, especially when we have many-to-many relationships.

Chapters:
1. Intro 00:00
2. Explaining the setup 00:55
3. First reason: exposing data that is not needed in the current endpoint context 03:20
4. Second reason: requiring data that is not needed in request bodies 05:33
5. Third reason: JSON serialization exceptions 08:31
6. Implementing DTOs (without AutoMapper) 12:14
7. Summary 23:27

AutoMapper tutorial:    • How to implement AutoMapper in Asp.Ne...  
#AspNetCore #dotnet #csharp

Комментарии

Информация по комментариям в разработке