Building an ASP.Net Core 5.0 service. In order to make this service mirror our other APIs I want to:
Have a route that supports the following URIs
// returns a single item
/api/Items/{id}
// returns multiple items
/api/Items/?date={date}
In the above, {id} could be an int, or a guid, and date is in the format YYYYMMDD
Couple
[ApiController]
[Route("Items")]
public class ItemController: ControllerBase
{
[HttpGet("{id}")]
public Item Get(string id)
{
}
[HttpGet()]
public IEnumerable<Item> Get([FromQuery] DateTime date)
{
return new List<Item> { new Item() };
}
}
When I run this, which I'm debugging using the Swagger functionality, it appears that I get two methods:
/Items/{id}
/Items/?date={date}
So far so good, except, that I want to support date strings of YYYYMMDD, but the default date converter does not support that.
One kludge is to make this a string and convert in the function(boo). Ideally, I'd like to register an additional Date parser for all endpoints.
Ideas?