Search code examples
asp.net-web-apiasp.net-web-api2asp.net-web-api-routing

WebAPI : Min/max double for RouteAttribute


I have the following API method:

[Route("GetEditorialRequestsByCoordinates/{lat:double}/{lng:double}")]
[AutomapperExceptionApiFilterAttribute]
public HttpResponseMessage GetEditorialRequestsByCoordinates(double lat, double lng)
{

}

it works fine for request like:

GET /v1/api/request/GetEditorialRequestsByCoordinates/48.999/2.777/

But I want to add limit (minimum and maximum) for lat and lng.

Follow this article: http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2

max Matches an integer with a maximum value. {x:max(10)}

min Matches an integer with a minimum value. {x:min(10)}

Try to create such route:

[Route("GetEditorialRequestsByCoordinates/{lat:double:min(-90):max(90)}/{lng:double:min(-180):max(180)}")]

and I get 404 error. Why?


Solution

  • The documentation you give tells that functions works for integer

    max: Matches an integer with a maximum value. {x:max(10)}

    I think it does not work for double.

    you can see this link to create your own IHttpRouteConstraint.