I am working on a REST API with ASP.NET Web API 2. Thing get bad when I try to integrate dates into the game.
Here is the route:
[Route("{id:Guid}/{from:DateTime}/{to:DateTime}")]
When I do that I can perfectly pass something like
.../[id]/2012-01-01/2013-01-01
However, when I get to the point where I need the time information it gets quite bad, let's imagine this one:
.../[id]/2012-01-01/2013-01-01 1:45:30 PM/2013-01-01 1:45:30 PM
It seems like the spaces are going OK but the ":" are blocking. So I though I should use my own format, being yyyyMMddhhmm. This gives the following URL:
.../[id]/201301031147/201401031147
However, .NET is not expecting this as a DateTime and does not know how to use it. So I used a IHttpRouteConstraint to allow it. The problem is that it still does not know how to deal with it after I told it it's fine...
So my question is, how do you pass a DateTime to the route?