RESTful API Patterns: Naming Conventions and Status Codes
Master RESTful API patterns by using plural nouns and standard HTTP status codes. Learn to build predictable, professional APIs with consistent resource paths.

Previously in this course, we covered implementing create operations with mongoose and express. Now that your server can save data to MongoDB, it’s time to ensure your interface is predictable. In this lesson, we’ll move beyond "just making it work" to designing an API that follows professional REST conventions.
The Philosophy of Resource-Oriented Design
REST (Representational State Transfer) is not a protocol, but an architectural style. At its core, REST treats everything as a resource. When you build an API, you aren't defining "actions" like getUsers or deleteUser; you are defining paths that represent data collections.
Think of your API as a file system:
/usersrepresents the entire collection./users/123represents a specific document within that collection.
Why Naming Conventions Matter
Consistency is the primary factor in developer experience (DX). If a frontend developer has to guess whether your endpoint is /get-all-users, /listUsers, or /users, your API is poorly designed.
Rule 1: Use Plural Nouns Always use plural nouns for your resource collections. Even if you are dealing with a single entity, the base path should represent the collection.
- Good:
GET /users,GET /users/123 - Bad:
GET /user,GET /user-list
Rule 2: Hierarchical Paths If a resource belongs to another, nest it logically. For example, if users have posts, the route structure should flow from parent to child.
GET /users/123/posts(All posts belonging to user 123)GET /posts/456(A specific post)
Choosing Correct HTTP Status Codes
Your API communicates the outcome of a request through HTTP status codes. Choosing the correct code is vital because clients (browsers, mobile apps) use these codes to decide how to handle the response.
| Status Code | Meaning | Use Case |
|---|---|---|
| 200 OK | Success | Standard response for GET, PUT, or PATCH. |
| 201 Created | Success | Used after a successful POST (resource created). |
| 204 No Content | Success | Used after a successful DELETE where no body is returned. |
| 400 Bad Request | Client Error | Payload is malformed or validation failed. |
| 404 Not Found | Client Error | Resource does not exist at this URL. |
| 500 Server Error | Server Error | Something went wrong internally (e.g., DB crash). |
Reference: For a deeper dive into these semantics, see REST API status codes: a semantic guide for api design.
Worked Example: Applying Patterns to Our Project
Let's refactor our existing user routes to follow these conventions. Notice how we shift from "action-oriented" routes to "resource-oriented" routes.
JAVASCRIPT// Before: Poor convention app.post(CE9178">'/create-user', ...) app.get(CE9178">'/get-user/:id', ...) // After: RESTful convention const express = require(CE9178">'express'); const router = express.Router(); // GET all users router.get(CE9178">'/users', (req, res) => { // 200 is implicit, but good to be aware of res.status(200).json({ data: users }); }); // POST a new user router.post(CE9178">'/users', (req, res) => { // 201 Created is the standard for successful resource creation res.status(201).json({ message: "User created" }); }); // DELETE a user router.delete(CE9178">'/users/:id', (req, res) => { // 204 No Content is ideal for successful deletions res.status(204).send(); });
Hands-on Exercise
Update your current project’s Express routes to strictly follow these three rules:
- Ensure all your primary resource endpoints (e.g.,
books,tasks,products) are pluralized. - Verify that your POST requests return a
201status code instead of the default200. - If you have a
DELETEroute, update it to return204with no response body.
Common Pitfalls
- Mixing Verbs and Nouns: A common mistake is adding verbs to the URI, like
/users/delete. The HTTP method (DELETE) already tells the server what to do; the URI should only identify the resource. - Over-nesting: Avoid going deeper than two levels (e.g.,
/users/1/posts/2/comments/3). If your path is too long, it's often better to flatten it or provide a separate resource for the deepest entity. - Using 200 for Everything: Never use
200for every success. Using201for creation and204for deletions provides machine-readable semantic information to the client.
FAQ
Q: Should I use versioning in my URL?
A: Yes. It is common practice to include the version in the path, like /api/v1/users. This allows you to deploy breaking changes in the future without disrupting existing clients.
Q: What if I need to perform an action that doesn't fit CRUD?
A: If you have a specific operation like "reset password," it is acceptable to use a "sub-resource" pattern: /users/123/password-reset.
Recap
We've established that designing RESTful APIs relies on consistent naming and status codes. By using plural nouns for collections, following hierarchical path structures, and returning precise HTTP status codes, you turn a collection of endpoints into a professional, predictable interface.
Up next: We will tackle Advanced Error Handling to ensure our API fails gracefully and informs the client exactly what went wrong.
Work with me

Laravel REST API Development
Clean, secure, well-documented Laravel REST APIs — the backend engine for your app, mobile client, or SaaS. Built by an API specialist.

Headless WordPress + Next.js Frontend Development
Keep WordPress for content, get a lightning-fast Next.js frontend. The best of both worlds — familiar editing, modern speed.


