← .NET Core learning path
.NET Core · Module 6 of 10

Building Web APIs

Create REST APIs with controllers or minimal APIs.

📖 Key ideas

  1. Controllers: [ApiController] class ProductsController : ControllerBase.
  2. Attributes: [HttpGet], [HttpPost], [Route("api/[controller]")].
  3. Return ActionResult<T>: Ok(), NotFound(), CreatedAtAction().
  4. Model binding reads route, query and JSON body.
  5. OpenAPI/Swagger documents the API.
💡 Real-life example: Controllers are counters in a bank, each handling a type of request.
[ApiController]Enables API conventions
ActionResult<T>Typed HTTP response
Model bindingMaps request data to parameters
Swagger/OpenAPIAPI documentation