Route:
config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional });
Controller:
public class ValuesController : ApiController
{
public string Get()
{
return "value";
}
public string Get(int id)
{
return Url.Link("DefaultApi", new { controller = "Values" });
}
}
Request:
http://kcthinkpad:9096/api/values/400
Response:
Expected: http://kcthinkpad:9096/api/Values
Actual: http://kcthinkpad:9096/api/Values/400
Workaround: user can explicitly set the parameter: id=""
config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional });
Controller:
public class ValuesController : ApiController
{
public string Get()
{
return "value";
}
public string Get(int id)
{
return Url.Link("DefaultApi", new { controller = "Values" });
}
}
Request:
http://kcthinkpad:9096/api/values/400
Response:
Expected: http://kcthinkpad:9096/api/Values
Actual: http://kcthinkpad:9096/api/Values/400
Workaround: user can explicitly set the parameter: id=""