ASP.NET Core Web API Interview Question #31

What is a request DTO?

DTOs, Model Binding, Validation & API Responses Junior Beginner

Quick Interview Answer

A request DTO defines the input contract accepted by an API operation. It should contain only the fields the client is permitted and required to send for that use case.

Detailed Explanation

A request DTO defines the input contract accepted by an API operation. It should contain only the fields the client is permitted and required to send for that use case.

Separate request DTOs such as CreateProductRequest and UpdateProductRequest help prevent overposting and avoid forcing clients to understand persistence-specific or server-managed fields.

Code Example

public sealed class CreateProductRequest
{
    [Required]
    [MaxLength(150)]
    public string Name { get; init; } = "";

    [Range(0.01, 1000000)]
    public decimal Price { get; init; }
}