When I use the following code:
public HttpResponseMessage Get()
{
return Request.CreateResponse(HttpStatusCode.OK, "Empty!");
}
public HttpResponseMessage Get(int id)
{
return Request.CreateResponse(HttpStatusCode.OK, id);
}
requests work exactly as they should. GET: api/controller returns with the body “Empty!”, and GET: api/controller/12 returns 200 with the body “12”.
But as soon as I change my code to this:
public HttpResponseMessage Get()
{
return Request.CreateResponse(HttpStatusCode.OK, "Empty!");
}
public HttpResponseMessage Get(int itemId) //changed parameter name
{
return Request.CreateResponse(HttpStatusCode.OK, itemId);
}
everything hits the default method and returns “Empty!”
I assumed that this was one of many naming convention matters, but I couldn’t find any documentation or other posts that said the parameters must be named specific values.
It may seem a semantic issue, but I’d like to know why I have to name my parameters specific things, or what I’m doing wrong. Why shouldn’t this simply work?
The convention is defined on the Routing table in RouteConfig.cs, if you change the parameter name, it should be changed accordingly: