API Naming Conventions

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.

Routes

In a RESTful API, the routes should always be plural.

So for an endpoint listing all of the notes the route would be:

/notes

The endpoint listing a singular note would be accessed via:

/notes/{note-id}

Controllers

The controllers in your application should use the same naming convention as your routes. So the controller for the Notes endpoints would be:

NotesController

Models

Your models interact with a single instance/object of (in this case) a note. So your model should be singular.

Note

Database Tables

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:

Notes

About the Author

Posted by

Categories:

API

Add a Response

Your name, email address, and comment are required. We will not publish your email.

The following HTML tags can be used in the comment field: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>