Search code examples
asp.net-core-5.0

ASP.NET CORE 5 API controller not working


Added an API controller to the project and it does not work. I get 404.

[Route("api/hlth")]
[ApiController]
public class hlth : ControllerBase
{
    // GET: api/<hlth>
    [HttpGet]
    public IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2" };
    }

    // GET api/<hlth>/5
    [HttpGet("{id}")]
    public string Get(int id)
    {
        return "value";
    }

}


Solution

  • Turns out I need to add

    app.MapControllers();

    that for some reason is not included in the default project configuration.