0

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.

3

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 Aug 12 '13 at 14:59
  • Yes, that is the preferred way. – nemec Aug 12 '13 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.