Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should you use plural or singular form of folder name in URL

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?

like image 532
Howard Avatar asked Feb 02 '12 03:02

Howard


People also ask

Should folder names be singular or plural?

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.

Should URL be plural or singular?

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.

Should API name be plural or singular?

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.

Should package name be singular or plural?

Use the plural for packages with homogeneous contents and the singular for packages with heterogeneous contents.


1 Answers

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

like image 170
geneqew Avatar answered Nov 03 '22 23:11

geneqew