Friday, May 13, 2016

Web API Attribute Routing - not as attribute-driven as one would expect

This is a short, but rather important note: when you call MapHttpAttributeRoutes() to configure routing based on attributes, Web API engine looks only for classes which name ends with *Controller.
This seems to be a carryover from convention-based routing, and it is rather unexpected that it is still there.
But if you are like me, and WebAPI came into your world just now, you would not really have that habit of naming all controllers like that, especially in the test project.

Summary: Always follow this pattern for WebAPI controller names: {Name}Controller

And inherit from ApiController, but that's obvious.

No comments: