Rules Hub
Coding Rules Library
Enforce consistent pluralization for REST API resources
Always use consistent plural nouns for resource collections in API routes to ensure predictability.
Bad example
| 1 | const router = Router(); |
| 2 |
|
| 3 | // Inconsistent naming: plural for adding, singular for deleting |
| 4 | router.post('/watchlists/:id/instruments', addInstruments); |
| 5 | router.delete('/watchlists/:id/instrument/:instrumentId', removeInstrument); |
Explanation (EN)
The API routes mix plural ('instruments') and singular ('instrument') for the same resource collection. This makes the API endpoints difficult to predict and confusing for consumers.
Objašnjenje (HR)
API rute miješaju množinu ('instruments') i jedninu ('instrument') za istu kolekciju resursa. To čini krajnje točke API-ja teškim za predviđanje i zbunjujućim za korisnike.
Good example
| 1 | const router = Router(); |
| 2 |
|
| 3 | // Consistent naming: always use 'instruments' to represent the collection |
| 4 | router.post('/watchlists/:id/instruments', addInstruments); |
| 5 | router.delete('/watchlists/:id/instruments/:instrumentId', removeInstrument); |
Explanation (EN)
The API uses plural nouns consistently for the resource collection across all HTTP methods. If the collection is 'instruments', accessing a specific item is done via '/instruments/:id'.
Objašnjenje (HR)
API dosljedno koristi imenice u množini za kolekciju resursa kroz sve HTTP metode. Ako je kolekcija 'instruments', pristup određenom predmetu vrši se putem '/instruments/:id'.
Notes (EN)
A common standard is to always use plural for collections (e.g., /users, /users/:id). Avoid mixing /users for lists and /user/:id for details.
Bilješke (HR)
Uobičajeni standard je uvijek koristiti množinu za kolekcije (npr. /users, /users/:id). Izbjegavajte miješanje /users za popise i /user/:id za detalje.