12

I understand that when naming RESTful URI's it is commonly accepted to use plurals to represent collections of resources. I am curious as to the argument for using singular nouns instead.

  • maybe because not everything is a collection? – jwenting Jun 17 '14 at 8:15
  • Isn't that where a singleton resource would come into play? – charness Jun 17 '14 at 17:02
12

Some resources contain only a single item. Good examples would be everything for which you don't need an ID to find out what data to render. Very common for example would be the Login resource. You have (from the users and browsers view) only a single login. You can create it, you can destroy it but you won't have an index action with several Logins to choose from.

Similar examples would be some mostly static pages like company information, imprints, contact forms and similar things that only display a single item or only allow a single create action.

It could be a matter of discussion if using singular nouns really adds much to readability of the code.

4

Because:

  1. English plural rules like "cherries" are not the nicest thing to think of while developing API, particularly when english is not your mother tongue.
  2. Sometimes you want to generate endpoint from the model, which is usually singular. It does not play nicely with the above.
  3. The argument "usually you start querying by a Get to display a list" does not refer to any real use case. And you will end up querying single items as much as and even more than a list of items.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.