What is the best way to name a URL when you can do both ‘unique identifer’ based as well as ‘hierarchy based’ resource naming ? Pros and cons of each


This Content is from Stack Overflow. Question asked by Venkatakrishna

Lets say we have a resource structure like below

6f4b3ca6-c992-42dd-b1e3-8c8f8ba62886APACAUNew South WalesStatedetails

Where guid is a unique identifier for a resource record

and Region is a parent for country which in turn is a parent for state and each such state has one record in the table. (region/country/state combination is unique and can act as an alternate key)

In order to display the State details json, which URL naming would be more appropriate. Are there pros and cons to each approach ?

Option 1:



Option 2:


Listing my thoughts here.

In Option 1,

the link is immutable and relatively static. So the same URL will return same data over a long period of time. So a client (requestor) may be provided the static link which they can book mark for future use. Tomorrow if the data changes (say france decides to rename normandy to normândy) such complexity is hidden from the requestor.

However there is less transparency as to what resource we are inquiring and the complexity is hidden.

In Option 2, the hierarchy is very clearly laid out. The complexity of arriving at the correct URL is left to the client (requestor) so they need to keep track of underlying data changes.

It is transparent for any system inspecting the resource such as a monitoring tool or WAF. However with excess transparency, if an unwanted third party knows the list of states, countries, regions (which is common knowledge) then there is risk of scraping which could prove resource intensive.


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?