REST API naming conventions are short, lowercase URLs with slashes separating resources, using verbs only in POST/PUT/PATCH requests. Most developers get the resource hierarchy wrong by mixing actions into paths or using underscores or camelCase, which makes APIs harder to read and maintain. For example, avoid /GetUserOrders and instead use /users/{userId}/orders. Below, you’ll see the exact rules for resources, actions, parameters, and pluralization.
What is a REST API naming convention?
A REST API naming convention is a set of rules for designing resource paths, query parameters, and HTTP methods to make your API intuitive and scalable. The core principle is separation of concerns—resources go in the path, actions go in the HTTP method, and attributes go as query parameters or in the request body.
Most teams violate this by doing one of these:
- Putting verbs in the path (e.g.,
/GetUsersinstead of/users). - Using underscores or camelCase instead of hyphens or kebab-case.
- Mixing singular and plural resources inconsistently.
- Overloading paths with query parameters for filtering.
Resource Naming: Singular or Plural?
The correct rule is to use plural nouns for collections and singular nouns for single items. This aligns with how URLs represent resources in the real world:
- Collections:
/users,/products,/orders - Single items:
/users/{id},/products/{sku}
Why this matters: Plural paths make it clear you’re fetching a list. Singular paths make it clear you’re fetching one item. Mixing them (like /user for a single user) confuses clients and servers.
Path Structure: How to Separate Resources
The path should only describe the resource hierarchy, not the action. Use forward slashes to nest resources logically:
- Good:
/users/{userId}/orders(fetch orders for a specific user) - Bad:
/users/{userId}/GetOrders(action in the path)
Nested paths work best when the child resource belongs to the parent. For example:
/customers/{id}/orders(orders belong to a customer)/products/{sku}/reviews(reviews belong to a product)
Never nest unrelated resources (e.g., /users/{id}/settings unless settings are user-specific).
HTTP Methods: Where Actions Belong
REST APIs use HTTP methods to express actions. Never put actions in the path—use the method instead:
| Method | Resource Path | Example |
|---|---|---|
| GET | /users | Fetch all users |
| GET | /users/{id} | Fetch a single user |
| POST | /users | Create a new user |
| PUT | /users/{id} | Update a user (full replace) |
| PATCH | /users/{id} | Partially update a user |
| DELETE | /users/{id} | Remove a user |
This separation keeps paths clean and methods self-documenting. For example, POST /users always means "create," while GET /users means "list."
Query Parameters: How to Filter and Sort
Use query parameters for optional filters, sorting, and pagination. Never overload the path with these—it violates REST principles:
- Good:
/users?name=john&sort=name - Bad:
/users/filter?name=john
Common query parameter patterns:
?limit=10&offset=0for pagination?status=activefor filtering?sort=-created_atfor sorting (descending)
Always document your query parameters in the API spec. Clients rely on them to interact with your data.
Parameter Naming: Hyphens vs. Underscores
The standard is to use kebab-case (hyphens) for paths and query parameters, but some teams use underscores. Pick one and stick to it:
- Good:
/user-profiles,?status=published - Avoid:
/user_profiles(underscores) - Avoid:
/UserProfiles(camelCase)
Hyphens are more readable in URLs. Underscores are common in databases but not in APIs. Consistency matters more than the exact style.
Versioning: How to Include It
If your API has versions, include the version in the path or header. Common approaches:
/v1/users(path-based)Accept: application/vnd.company.users.v1+json(header-based)
Never version via query strings (?version=1)—it breaks REST conventions. Path-based versioning is the simplest and most common.
Idiomatic Examples: What Good APIs Look Like
Here are real-world patterns for common resources:
- User Management
GET /users– List all usersPOST /users– Create a userGET /users/{id}– Fetch a userPUT /users/{id}– Update a userDELETE /users/{id}– Delete a user
- Order Processing
GET /orders– List ordersPOST /orders– Create an orderGET /orders/{id}– Fetch an orderPUT /orders/{id}/status– Update order status (nested under orders)
- Product Catalog
GET /products– List productsGET /products/{sku}/reviews– List reviews for a productPOST /products/{sku}/reviews– Add a review (nested)
Common Mistakes and How to Fix Them
Most APIs fail these checks. Here’s how to spot and fix them:
- Mistake: Verbs in paths
- Bad:
/GetUserOrders - Fix: Use
GET /users/{id}/ordersinstead.
- Bad:
- Mistake: Singular collections
- Bad:
/userfor a list - Fix: Use
/usersfor collections.
- Bad:
- Mistake: Overloading paths with actions
- Bad:
/orders/fulfill(mixes action with resource) - Fix: Use
PUT /orders/{id}/statusorPOST /orders/{id}/fulfill.
- Bad:
- Mistake: Using POST for non-creates
- Bad:
POST /users/{id}/update - Fix: Use
PUT /users/{id}(full update) orPATCH /users/{id}(partial).
- Bad:
Testing Your API Naming
Before finalizing, ask these questions:
- Does the path clearly describe the resource, not the action?
- Are collections plural and single items singular?
- Can a client read the path and infer the resource hierarchy?
- Are query parameters optional and well-documented?
- Does the API follow the same style across endpoints?
If you can answer "yes" to all, your naming is likely good. If not, revisit the paths.
When to Break the Rules
Some conventions exist to be broken—if it makes your API more intuitive for clients. Examples:
- Legacy systems: If your backend expects
/getUser, document it but add a new RESTful endpoint alongside. - GraphQL-style paths: If your API is hybrid (REST + GraphQL), you might need
/graphqlas a base. - Security constraints: If paths must include actions for permission checks, document it clearly.
Always document deviations. Clients rely on consistency.
How do I handle nested resources like comments under posts?
Use the parent-child relationship in the path: /posts/{id}/comments. This matches how REST treats hierarchies. For actions (e.g., deleting a comment), use the HTTP method: DELETE /posts/{postId}/comments/{commentId}.
Should I use underscores or hyphens in paths?
Stick to hyphens (kebab-case) for paths and query parameters. Hyphens are more readable in URLs and align with web standards. Underscores are fine in query parameters if your team prefers them, but paths should use hyphens.
What’s the difference between PUT and PATCH?
Use PUT to replace an entire resource (e.g., PUT /users/{id} updates all fields). Use PATCH to update only specific fields (e.g., PATCH /users/{id} { "name": "New Name" }). Most teams overuse PUT—start with PATCH for partial updates.
Can I use versioning in query strings?
No. Query strings (e.g., ?version=1) violate REST conventions and can cause issues with caching. Use path-based versioning (/v1/users) or headers (Accept: application/vnd.company.users.v1+json) instead.