ASP.NET Core Web API Interview Question #33
Should create, update, and response DTOs be the same class?
DTOs, Model Binding, Validation & API Responses Junior Beginner
Quick Interview Answer
They can be the same for very simple contracts, but separate DTOs are usually clearer when the operations have different requirements. A create request may require fields that an update does not, while a response may contain server-generated identifiers and timestamps that clients must not submit.
Detailed Explanation
They can be the same for very simple contracts, but separate DTOs are usually clearer when the operations have different requirements. A create request may require fields that an update does not, while a response may contain server-generated identifiers and timestamps that clients must not submit.
Purpose-specific DTOs improve validation, security, documentation, and long-term API evolution.
Code Example
public sealed class CreateProductRequest { /* client input */ }
public sealed class UpdateProductRequest { /* editable fields */ }
public sealed class ProductResponse { /* public output */ }