Some RESTful services use different resource URIs for update/get/delete and Create. Such as
- Create – using /resources with POST method (observe plural) at some places using /resource (singular)
- Update – using /resource/123 with PUT method
- Get – Using /resource/123 with GET method
I’m little bit confused about this URI naming convention. Should we use plural or singular for resource creation? What should be the criteria while deciding that?
The premise of using
/resourcesis that it is representing “all” resources. If you do aGET /resources, you will likely return the entire collection. By POSTing to/resources, you are adding to the collection.However, the individual resources are available at /resource. If you do a
GET /resource, you will likely error, as this request doesn’t make any sense, whereas/resource/123makes perfect sense.Using
/resourceinstead of/resourcesis similar to how you would do this if you were working with, say, a file system and a collection of files and/resourceis the “directory” with the individual123,456files in it.Neither way is right or wrong, go with what you like best.