I have configured my WebApiConfig like this:
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: \"DefaultApi\"
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
Maps to:
http://localhost:8598/api/Controller/Action/id
The WebApi
portion of the url is redundant with api
. Then modify the method parameter name to match the route:
public IEnumerable
This is a good default as it matches the convention.
Alternatively, you can modify the route to use this unconventional parameter name instead:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{CatID}",
defaults: new { CatID = RouteParameter.Optional }
);
Finally, in either case make sure the controller name ends in Controller
.
Good names: CustomController
, CustomApiController
Bad names: Custom
, CustomApi