I would like to route with
api/prefix/{controller}/{id}/{param}
as opposed to
api/prefix?Controller={controller}&Id={id}&Param={param}
In other words, I would prefer a URL without the name/value parameters.
The controller is defined like this:
/// <summary>
/// Employee API
/// </summary>
[System.Web.Mvc.RoutePrefix("api/employee")]
public class EmployeeController : ApiController
{
///<summary>
/// Returns a collection of employees from a supplied CSV of EmployeeIds
/// </summary>
/// <paramref name="EmployeeIds">CSV of EmployeeIds. Pass "ALL" to include all employees. Defaults to "ALL".</paramref>
/// <paramref name="PageSize">Number of rows to return. Defaults to all rows</paramref>
/// <paramref name="PageNumber">Number of the page to return. Defaults to Page 0</paramref>
/// <returns>IEnumerable<Employee></returns>
[System.Web.Mvc.Route("id/{EmployeeIDs:alpha?}/{PageSize:int?}/PageNum:int?}")]
public IHttpActionResult getEmployeesByIds(string EmployeeIds = "ALL",int PageSize = 0,int PageNumber = 0)
{
EmployeeDb db = new EmployeeDb();
IEnumerable<Employee> e = db.getEmployeesById(EmployeeIds, PageSize, PageNumber);
return Ok(e);
}
}
How can I control the way the format of the URL?
controller/action/is much cleaner thancontroller=mycontroller&action=myAction.....