I'm trying to setup Web API routing for what I thought would be a very simple thing. However, it seems that routing in Web API is not consistent with different HTTP verbs. Suppose I have this controller with these actions...
public class AvalancheController : ApiControllerBase
{
// GET api/avalanche
public IEnumerable<Avalanche> Get() {}
// GET api/avalanche/5
public Avalanche Get(int id) {}
// GET api/avalanche/ActionTest/5
[ActionName("ActionTest")]
public Avalanche GetActionTest(int id) {}
// GET api/avalanche/ActionTest/2
[ActionName("ActionTest2")]
public Avalanche GetActionTest2(int id) {}
// POST api/avalanche
public void Post([FromBody]Avalanche value) {}
// PUT api/avalanche/5
public void Put(int id, [FromBody]Avalanche value) {}
// PUT api/avalanche/test/5
[ActionName("Test")]
public void PutTest(int id, [FromBody]Avalanche value) {}
// DELETE api/avalanche/5
public void Delete(int id) {}
}
and I have the following routes defined...
config.Routes.MapHttpRoute(
name: "ActionRoutes",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional },
constraints: new
{
controller = "Avalanche",
action = "(ActionTest|ActionTest2|Test)"
}
);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
Then I end up with the following routes being defined...
GET api/Avalanche/ActionTest/{id}
GET api/Avalanche/ActionTest2/{id}
PUT api/Avalanche/Test/{id}
GET api/Avalanche
POST api/Avalanche
DELETE api/Avalanche/{id}
Why doesn't the default PUT route get picked up? What's different between the routing of the default GET and the default PUT? I've tried decorating the functions in every imaginable way but I get the same results.
Mainly I want to know how to get the default PUT route to be picked up. If you have any suggestions on how to modify these routes so that I don't have to have a route for each controller to specify action names that would be fantastic also.
Thanks!
Ian
EDIT: I noticed this morning that the following route is also not being defined..
GET api/Avalanche/{id}