I was creating a new action for a WebApi
controller and tried to create a url using the following:
@Url.RouteUrl("DefaultApi", new { httproute = "", controller = "ClientApi"})
and noticed that the default route did not have an action attribute, it looks like this:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
how come the default route doesn't have the action in the route configuration by default? is it bad practice to have it? that is to say is it bad practice to have so many actions in a web api controller that it requires to change the route.
1 Answer 1
how come the default route doesn't have the action in the route configuration by default?
Because in REST, the action to be executed by the server is dictated by the HTTP method used in the request.
-
yes that's what I was thinking. In this case then it would be better to overload my method like this:
GetAll(string query = String.Empty)
?SOfanatic– SOfanatic2013年08月12日 14:59:15 +00:00Commented Aug 12, 2013 at 14:59 -
Yes, that is the preferred way.nemec– nemec2013年08月12日 19:03:51 +00:00Commented Aug 12, 2013 at 19:03
Explore related questions
See similar questions with these tags.