title: Should I provide parent resource name in URL or not in RESTful WS?
body: <p>I am developing some basic restful web services using PHP and apache and I am wondering whether I should build the URLs providing the parent entity name or not. Let me explain this better:</p>
  
  <p>I have 2 entities, lets suppose <strong>countries</strong> and <strong>cities</strong>. I am now just providing WS to get, create, update or delete <strong>cities</strong> but the API won't support <strong>countries</strong> manipulation via WS. I am remapping urls using <strong>mod_rewrite</strong> and I am providing the following urls in the api to manipulate cities: </p>
  
  <pre><code>. GET     /api/countries/&lt;country_id&gt;/cities            cities of country with id &lt;country_id&gt;
  
  . GET     /api/countries/&lt;country_id&gt;/cities/&lt;city_id&gt;  city with id &lt;city_id&gt;
  
  . POST    /api/countries/&lt;country_id&gt;/cities            add a city to country with id &lt;country_id&gt;
  
  . PUT     /api/countries/&lt;country_id&gt;/cities/&lt;city_id&gt;  update the city whose country has id &lt;country_id&gt;
  
  . DELETE  /api/countries/&lt;country_id&gt;/cities/&lt;city_id&gt;  delete city ...
  </code></pre>
  
  <p>I started looking careful at these urls and I got confused whether one should provide the parent entity name and id or not. I am making a great assumption and is that cities cannot be assigned to more than one country, i.e. it is not a many-to-many relationship. Assuming this I think a shorter URL pattern could be provided for many of the API functions. For example if the client wants to delete some city it would be enough if he send:</p>
  
  <pre><code>. DELETE /api/cities/14
  </code></pre>
  
  <p>I know that a city belongs to one country, and the client does not need to find out the country id before making the request.</p>
  
  <p>The majority of the urls can be transformed into this shorter kind of url except for the first one (get all countrie's cities).</p>
  
  <p>This is my first time developing web services and I haven't read too much about it so I may be probably misunderstanding something. Can I please get some advice? Thanks a lot and sorry for my rudimentary english.</p>
  
  <p>EDIT1: I think the question can be generalized in 'How should I handle entities relationship in API urls?'</p>