The ApiController attribute

From version 2.1, ASP.NET Core introduced a new attribute, that is, the ApiController attribute:

using Microsoft.AspNetCore.Mvc;namespace SampleAPI.API.Controllers{    [Route("api/[controller]")]    [ApiController]    public class ValuesController : ControllerBase    {      // ...    }{

The ApiController attribute is commonly coupled with the ControllerBase class to enable REST-specific behavior for controllers, and it allows us to build HTTP APIs. First of all, it provides implicit model state validation, which means that we do not need to explicitly check the ModelState.IsValid attribute in each action. Secondly, it also implicitly defines the model binding attributes, which means that we do not need to specify the [FromBody], ...

Get Hands-On RESTful Web Services with ASP.NET Core 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.