If you are using the multiple or single form of the folder name in the 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 REST API URL. (Example 2)

Which one is recommended and why?

+5
source share
2 answers

For REST, I mainly use the plural form to indicate the path to the resource. But you should also take Cacheablility, the frequency of changes and the turbidity of the resource. In my case, resource collections mostly deal, so I used a plural form.

The reason for this is because, for example:

http://www.example.com/users/johndoe

will serve the URI to GET a johndoe user belonging to your user collection.

http://www.example.com/users

will be used as a URI for GET for all users and can be easily used in the request URL:

http://www.example.com/users?limit=5

- URL-, POST :

http://www.example.com/users

Oreilly RESTful Web Services Cookbook

+3

URL .

http://www.example.com/users , . .

 http://www.example.com/user/johndoe - , , johndoe.

: 1. . 2./ 201 404 3./user/ 401, .

+1

All Articles