Example 1:
http://www.example.com/image/logo.png
http://www.example.com/images/logo.png
Example 2:
http://www.example.com/user/johndoe
http://www.example.com/users/johndoe
Especially if you use the Url as REST API. (Example 2)
Which one is recommended and why?
Directory names should be singular when the name describes how the files are grouped beyond their type. In programming, an example of this would be a Post directory that could contain files relating to fetching posts from the database and performing actions on them.
Yes, URL could be plural, but type singular. More to say, they might be completely different words. For example GET /vehicles endpoint might return resources of type Car , Aircraft , Train , Ship , and so on. In my APIs I'm always using singular types.
Plural Nouns Are Preferable, Rather Than Singular Using plural or singular nouns for defining resources has no any impact on how your API will work; however, there are common conventions that are used in all good RESTful APIs. One of such conventions is the use of plural nouns for defining resources.
Use the plural for packages with homogeneous contents and the singular for packages with heterogeneous contents.
For REST, i mainly use the plural form to indicate a path to the resource. But you also have to take the Cacheablility, Frequency of Change and the Mutability of the Resource. In my case, collections of the resource is mainly the case, so i had used the plural form.
The reason for this is that for example:
http://www.example.com/users/johndoe
will serve the URI to GET the user johndoe which belongs to your collection of users.
http://www.example.com/users
will be used as the URI to GET all users and can be easily be used on query url like:
http://www.example.com/users?limit=5
creating a new user will still use the same URL then using POST & passing the parameters:
http://www.example.com/users
for refs you may want to check the Oreilly book RESTful Web Services Cookbook
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With