Skip to content

Instantly share code, notes, and snippets.

@ismyrnow
Created March 4, 2013 03:20
Show Gist options
  • Save ismyrnow/5079663 to your computer and use it in GitHub Desktop.
Save ismyrnow/5079663 to your computer and use it in GitHub Desktop.
WebAPI Routing Using Action Names
routes.MapHttpRoute(
name: "DefaultApiWithAction",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional },
constraints: new { action = @"^[^\d].*$" }
);
routes.MapHttpRoute(
name: "DefaultApiWithId",
routeTemplate: "api/{controller}/{id}",
defaults: new { action = "Get", id = RouteParameter.Optional },
constraints: new { httpMethod = new HttpMethodConstraint("Get") }
);
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment