I'm trying to see if I need to write a custom IHttpRouteConstraint
or if I can wrestle with the built-in ones to get what I want. I can't see to find any good documentation on this anywhere.
Basically, here's my action:
[Route("var/{varId:int:min(1)}/slot/{*slot:datetime}")]
public async Task<HttpResponseMessage> Put(int varId, DateTime slot)
{
...
}
What I want is to be able to call it like this:
PUT /api/data/var/1/slot/2012/01/01/131516
and have the framework bind 19 to var id and a DateTime
with a value of "Jan 1st, 2012, 1:15:16pm" as the "slot" value.
Following the guide from here: http://www.asp.net/web-api/overview/web-api-routing-and-actions/create-a-rest-api-with-attribute-routing I am able to get it to work by passing in just the date segments, i.e. PUT /api/data/var/1/slot/2012/01/01
or PUT /api/data/var/1/slot/2012-01-01
, but that only gives me a data value, no time components.
Something tells me that trying to pass in time in any sane way through URI segments is a bad idea, but I'm not sure why it'd be a bad idea, besides the ambiguity regarding local vs UTC times.
I've also tried constraining the datetime
constraint with a regex, e.g. {slot:datetime:regex(\\d{4}/\\d{2}/\\d{2})/\\d{4})}
to try to get it to parse something like 2013/01/01/151617
as a DateTime, but to no avail.
I'm pretty sure I can get this to work with a custom IHttpRouteConstraint
, I just don't want to do something that might be built in.
Thanks!