title: Properly handling nested resources in ASP.net MVC 4 WebApi routing
body: <p>I'd like to provide REST API in this way:</p>
  
  <pre><code>GET /api/devices
  POST /api/devices
  PUT /api/devices/1
  DELETE /api/devices/1
  </code></pre>
  
  <p>This is my configuration:</p>
  
  <pre><code>config.Routes.MapHttpRoute(
      name: "DefaultApi",
      routeTemplate: "api/{controller}/{id}",
      defaults: new { id = RouteParameter.Optional }
  );
  </code></pre>
  
  <p>And these are the actions:</p>
  
  <pre><code>public IEnumerable&lt;Device&gt; Get()
  {
  //return all devices
  }
  
  public Devices Get(id)
  {
  //return a specific devices
  }
  </code></pre>
  
  <p>and so on.</p>
  
  <p>The issue appears when I want to handle nested resources:</p>
  
  <pre><code>GET /api/devices/1/readings
  POST /api/devices/1/readings
  GET /api/devices/1/readings/1
  PUT /api/devices/1/readings/1
  DELETE /api/devices/1/readings/1
  </code></pre>
  
  <p>This is my configration for these:</p>
  
  <pre><code>config.Routes.MapHttpRoute(
      name: "NestedApi",
      routeTemplate: "api/{controller}/{parentResourceId}/{action}/{id}",
      defaults: new { id = RouteParameter.Optional }
  );
  </code></pre>
  
  <p>The issue shows up when trying to GET and POST to the nested resource:</p>
  
  <pre><code>[HttpGet]
  public String Readings(int parentResourceId)
  {
     //return a list of readings for the device
  }
  
  [HttpPost]
  public String Readings(int parentResourceId)
  {
      //create and return the id of a reading for the device
  }
  </code></pre>
  
  <p>This is, of course, failing because there are two actions with the same signature.</p>
  
  <p>I'd like to hear from a way of accomplishing this with the most RESTful approach</p>