I'm new to REST and I've observed that in some RESTful services they use different resource URI for update/get/delete and Create. Such as
I'm little bit confused about this URI naming convention. What should we use plural or singular for resource creation? What should be the criteria while deciding that?
Using nouns for naming URIs is a REST API naming best practice, but when should you use singular or plural nouns? In general, using plural nouns is preferred unless the resource is clearly a singular concept (e.g. https://api.example.com/users/admin for the administrative user).
I suggest using singulars for everything. If there is an /{id}, then the API should return a single record. If there is not an /{id} that follows, then API should return the collection.
Declaring a resource or resources generally corresponds to generating many default routes. resource is singular. resources is plural.
In deciding what resources are within your system, name them as nouns as opposed to verbs or actions. In other words, a RESTful URI should refer to a resource that is a thing instead of referring to an action. Nouns have properties as verbs do not, just another distinguishing factor.
For me is better to have a schema that you can map directly to code (easy to automate), mainly because code is what is going to be at both ends.
GET /orders <---> orders POST /orders <---> orders.push(data) GET /orders/1 <---> orders[1] PUT /orders/1 <---> orders[1] = data GET /orders/1/lines <---> orders[1].lines POST /orders/1/lines <---> orders[1].lines.push(data)
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