So you’ve figured out what API endpoints you need and what HTTP methods you’re going to use, but you’ve now started building your API and you’re unsure how to name your models and controllers… Are the controllers singular? plural? what about the models? Well, this post should help clear it up.
In a RESTful API, the routes should always be plural.
So for an endpoint listing all of the notes the route would be:
The endpoint listing a singular note would be accessed via:
The controllers in your application should use the same naming convention as your routes. So the controller for the Notes endpoints would be:
Your models interact with a single instance/object of (in this case) a note. So your model should be singular.
The tables in your database should be plural, as these contain multiple instances of that object. So in this case, the table would be called: