Using Minimal APIs with Data Transfer Objects
This section explores leveraging the Data Transfer Object (DTO) pattern with Minimal APIs.
This section is the same as we explore in Chapter 6, Model-View-Controller, but in the context of Minimal APIs. Moreover, the two code projects are part of the same Visual Studio solution for convenience, allowing you to compare the two implementations.
Goal
As a reminder, DTOs aim to control the inputs and outputs of an endpoint by decoupling the API contract from the application’s inner workings. DTOs empower us to define our APIs without thinking about the underlying data structures, leaving us to craft our REST APIs how we want.
We discuss REST APIs and DTOs in more depth in Chapter 4, REST APIs.
Other possible objectives are to save bandwidth by limiting the amount of information the API transmits, flattening the data structure, or adding API features that cross multiple entities.