Glad you found a solution to your problem. But I would provide my feedback based on my training with REST services. The idea for a REST web service is to resolve each URL to a resource (or possibly an entity), and depending on HttpVerb, the work will be decided. In this case, you have three GET operations that work perfectly with your changes.
But I think that the controllers can also be regrouped to have a single GET operation and have a single responsibility, thus, better maintainability. For example:
Avalanchecontroller
public class AvalancheController : ApiControllerBase { public IEnumerable<Avalanche> GET() { } public void POST(Avalanche avalanche) { } }
We can assume that all the avalanches on the upper level deal with all the avalanches, below are the operations that need to be determined.
GET: returns the entire avalanche
POST: inserts a new avalanche
PUT: not used
REMOVE: not used
AvalancheDetailsController
public class AvalancheDetailsController : ApiControllerBase { public Avalanche GET(int id) { } public int PUT(int id) { } public int DELETE(int id) { } }
We can assume that we are talking about a single avalanche, below are the operations that need to be determined.
GET: returns a single avalanche
POST: not used
PUT: updates one avalanche
DELETE: removes a single avalanche
Now I assume that we have a clear distinction between controllers. There may be different GET operations in the OP you were talking about, but it only returns one Avalanche . So, I would modify the GET method to take the object as input and check ie,
public class AvalanceRequest { public int? Id {get;set;} public string Name {get;set;} } public class AvalancheDetailsController : ApiControllerBase { public Avalanche GET(AvalanceRequest request) {
Working with a URL, I really did not work with WebAPI, but ServiceStack tried to develop REST services. It allows you to attach url regardless of controller names.
Url
api / Avalanche -> AvalancheController (Operations are called based on HttpVerb)
api / Avalanche / Id โ AvalancheDetailsController (Operations are called based on HttpVerb)
I do not know if the URL can be attached in the same way in the WebAPI, otherwise you will have a default configuration and a call through. api / Avalanche and api / AvalancheDetails / id.
config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } );
I apologize for the long post, I hope this makes sense.