← .NET Core learning path.NET Core · Module 6 of 10
Building Web APIs
Create REST APIs with controllers or minimal APIs.
📖 Key ideas
- Controllers: [ApiController] class ProductsController : ControllerBase.
- Attributes: [HttpGet], [HttpPost], [Route("api/[controller]")].
- Return ActionResult<T>: Ok(), NotFound(), CreatedAtAction().
- Model binding reads route, query and JSON body.
- 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