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.

asked Aug 12, 2013 at 14:21

1 Answer 1

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.

answered Aug 12, 2013 at 14:43
2
  • 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) ? Commented Aug 12, 2013 at 14:59
  • Yes, that is the preferred way. Commented Aug 12, 2013 at 19:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.