I'm trying to figure out if I need to write a custom IHttpRouteConstraint , or if I can struggle with the built-in to get what I want. I donβt see anything to find good documentation.
Basically, here is my action:
[Route("var/{varId:int:min(1)}/slot/{*slot:datetime}")] public async Task<HttpResponseMessage> Put(int varId, DateTime slot) { ... }
I want it to be called like this: PUT /api/data/var/1/slot/2012/01/01/131516 and bind the framework 19 to var id and a DateTime with the value "January 1, 2012, 1:15 : 16 pm "as the value of" slot ".
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 can make it work by passing only date segments i.e. PUT /api/data/var/1/slot/2012/01/01 PUT /api/data/var/1/slot/2012-01-01 or PUT /api/data/var/1/slot/2012-01-01 , but that only gives me the data value, no temporary components.
Something tells me that trying to get in time in any reasonable way through the URI segments is a bad idea, but I'm not sure why this would be a bad idea, besides the ambiguity about local versions of UTC.
I also tried to limit the DateTime constraint to a regular expression, 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 DateTime, but to no avail.
I'm sure I can get this to work with a custom IHttpRouteConstraint , I just don't want to do something that can be embedded.
Thank!
asp.net-web-api asp.net-web-api-routing
Dimitar Velitchkov Oct 30 '13 at 19:48 2013-10-30 19:48
source share