I have a .Net Core 2.2 Web API. One of my controller action methods takes two query string parameter, a year and a month.
GET: /api/ItemsForMonth?year=2019&month=8
The action method looks like this:
[HttpGet]
public async Task<ActionResult<IEnumerable<Item>>> GetItemsForMonth([FromQuery] int year, [FromQuery] int month)
{
if (year <= 2000 || month <= 0 || month > 13)
return BadRequest("Please check the year and month parameters.");
}
So I am checking to make sure that the year is greater than 2000, and the month is between 1 and 12.
Is that the best way of doing it? I know if the parameters were part of the route instead of query strings (and maybe they should be?) I could do this
GET: /api/ItemsForMonth/2019/8
[HttpGet("/{year:int:min(2000)}/{month:int:min(1):max(12)}")]
public async Task<ActionResult<IEnumerable<Item>>> GetItemsForMonth()
{
}
But is there something similar for query string parameters?
Thanks