I'm using Web Api to create REST APIs that have parameters ranging from 0 to 4. Below are examples of my APIs :
- GetTaxRates()
- GetTaxRatesByDate(string date, string name= "") // name is an optional parameter
- GetTaxBetweenDates(string frmDate, string toDate, string name="") // name is an optional parameter
- GetRecentTaxRates(string name= "") // name is an optional parameter
For these different GET calls, i have created the following routes in the webapiconfig :
routeTemplate: "api/{controller}/{action}", defaults: new { }
routeTemplate: "api/{controller}/{action}/{date}/{name}", defaults: new { name= RouteParameter.Optional }
routeTemplate: "api/{controller}/{action}/{frmdate}/{toDate}/{name}", defaults: new { name= RouteParameter.Optional }
When i am calling the APIs, it works fine for most of the routes, but there seems to be a conflict between the routes and i get the error "No action was found on the controller 'TaxRate' that matches the request." when i call the action api/TaxRate/GetTaxBetweenDates/2015-04-01/201504-10
Although i am getting the results when calling the same api with all the parameters: api/TaxRate/GetTaxBetweenDates/2015-04-01/201504-10/abc
When i change the sequence of the routes, the same issue occurs GetTaxRatesbyDate API call.