do you need the Web API programming pattern too?
[Route("api/[controller]")]
[ApiController]
public class ReportsController : ControllerBase
{
[HttpGet("{months}")]
public ActionResult ReportingMonths(int months = 14)
{
List<DateTime> dates = new List<DateTime>();
DateTime firstOfTheCurrentMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
for (int i = 0; i < months; i++)
{
dates.Add(firstOfTheCurrentMonth.AddMonths(i * -1));
}
return Ok(dates);
}
}
If the {months} route parameter is missing then the default is 14; int months = 14.
https://localhost:7208/api/Reports
If the {months} route parameter exits then the route parameter is used.
https://localhost:7208/api/Reports/2
It might be a good idea to go through a Web API getting started tutorial and/or read the route reference documentation.
Tutorial: Create a web API with ASP.NET Core
Routing to controller actions in ASP.NET Core