I have Users
controller and basic REST pattern is working just fine. However I need one additional pattern users/{id}/usergroups
that will return all u
You can either: just define one Get
method, and have an optional Id Parameter like this:
public IEnumerable GetUsers(int? id){
if (id.HasValue)
{
//return collection of one item here
}
//return collection of all items here
}
Or you can have multiple Gets decorated with the ActionName Attribute
// GET api/Users
[ActionName("GetAll")]
public IEnumerable GetUsers()
// GET api/Users/5
[ActionName("Get")]
public User GetUser(int id) // THIS IS NO LONGER IN CONFLICT
And then define the routes on your RouteConfig like so:
routes.MapHttpRoute(
name: "DefaultApiWithAction",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);