ASP.NET Core Web API Interview Question #28
How does [ApiController] infer parameter binding sources?
DTOs, Model Binding, Validation & API Responses Junior Beginner
Quick Interview Answer
ApiController applies conventions that infer common binding sources. Complex types are commonly inferred from the request body, route-matching parameters from route data, and other simple parameters may come from the query string.
Detailed Explanation
ApiController applies conventions that infer common binding sources. Complex types are commonly inferred from the request body, route-matching parameters from route data, and other simple parameters may come from the query string.
These conventions reduce repetitive attributes, but developers should understand them so the endpoint contract is not accidentally changed when parameter types or routes change.
Code Example
[ApiController]
[Route("api/products")]
public class ProductsController : ControllerBase
{
[HttpPost]
public IActionResult Create(CreateProductRequest request)
=> Ok(request);
}