ASP.NET Core Web API Interview Question #32
What is a response DTO?
DTOs, Model Binding, Validation & API Responses Junior Beginner
Quick Interview Answer
A response DTO defines the representation returned to API clients. It allows the API to expose a stable, intentional contract instead of serializing database entities directly.
Detailed Explanation
A response DTO defines the representation returned to API clients. It allows the API to expose a stable, intentional contract instead of serializing database entities directly.
Response DTOs can omit internal fields, flatten relationships, rename concepts for clients, and include calculated or hypermedia-related information when required.
Code Example
public sealed class ProductResponse
{
public int Id { get; init; }
public string Name { get; init; } = "";
public decimal Price { get; init; }
public string Category { get; init; } = "";
}