Back to course

Building a Web API Controller

.NET Zero to Hero: Master C# and Modern App Development

Web API Basics

An API returns data (usually JSON) rather than HTML pages.

Creating a Controller:

csharp [ApiController] [Route("[controller]")] public class UsersController : ControllerBase { [HttpGet] public string Get() => "Hello API"; }

  • [ApiController]: Enables API-specific features.
  • [HttpGet]: Marks the method to respond to HTTP GET requests.