In Web API 2, I can put constraints in the route template; for example:
[Route("api/foos/{id:int}")]
void GetFooWithId(int id, [FromUri] string format = null)
{ ... }
Is there a way to constrain query string parameters, such as format
in the above example, in a similar manner?
(I know that I could perhaps declare a custom value type for the format
parameter and then define a [TypeConverter]
on it that fails for invalid values, but I would first like to see whether Web API 2's route constraint mechanism can be employed for query string parameters, too.)