Bird
Raised Fist0
Rest APIprogramming~15 mins

Avoiding verbs in URLs in Rest API - Deep Dive

Choose your learning style10 modes available
Overview - Avoiding verbs in URLs
What is it?
Avoiding verbs in URLs means designing web addresses that use nouns instead of action words. This style focuses on resources, like users or products, rather than actions like 'create' or 'delete'. It helps make URLs clear, consistent, and easy to understand. This approach is common in REST API design.
Why it matters
Using verbs in URLs can confuse users and developers because URLs should represent things, not actions. Without this rule, APIs become harder to use and maintain, leading to mistakes and slower development. Clear, noun-based URLs improve communication and make APIs more predictable and user-friendly.
Where it fits
Learners should first understand basic HTTP methods like GET, POST, PUT, and DELETE. After mastering noun-based URLs, they can learn advanced REST concepts like HATEOAS and API versioning. This topic fits in the journey of designing clean, scalable web APIs.
Mental Model
Core Idea
URLs should name resources (things) while HTTP methods define actions on those resources.
Think of it like...
Think of a library catalog: the catalog lists books by title (nouns), and you use different actions like borrowing or returning separately. The catalog itself doesn't say 'borrow-book' but just 'book'.
┌─────────────┐       ┌───────────────┐
│   URL (noun)│──────▶│ HTTP Method   │
│ /users/123  │       │ GET, POST...  │
└─────────────┘       └───────────────┘

URL names the resource, HTTP method names the action.
Build-Up - 7 Steps
1
FoundationUnderstanding URLs as Resource Names
🤔
Concept: URLs should represent resources, which are things or data entities, not actions.
In REST APIs, URLs like /users or /products point to collections or single items. They are nouns describing what you want to access. For example, /users/123 means user with ID 123.
Result
You get a clear, consistent way to identify data entities in your API.
Understanding that URLs name resources helps separate the 'what' (resource) from the 'how' (action), making APIs easier to design and use.
2
FoundationRole of HTTP Methods in Actions
🤔
Concept: HTTP methods (GET, POST, PUT, DELETE) specify what action to perform on the resource named by the URL.
GET /users/123 fetches user data, POST /users creates a new user, PUT /users/123 updates user 123, DELETE /users/123 removes user 123. The URL stays the same; the method changes the action.
Result
Actions are cleanly separated from resource names, avoiding confusion.
Knowing that HTTP methods carry the action meaning prevents mixing verbs into URLs, which keeps APIs intuitive.
3
IntermediateWhy Verbs in URLs Cause Problems
🤔Before reading on: do you think including verbs in URLs makes APIs clearer or more confusing? Commit to your answer.
Concept: Including verbs in URLs mixes resource identification with actions, leading to redundancy and inconsistency.
URLs like /createUser or /deleteProduct repeat the action already expressed by HTTP methods. This causes confusion, harder maintenance, and breaks REST principles.
Result
APIs with verbs in URLs are less predictable and harder to document or automate.
Understanding the confusion verbs cause in URLs helps you appreciate the clean separation REST encourages.
4
IntermediateUsing Nouns with Query Parameters for Actions
🤔
Concept: Sometimes actions need extra details; these can be passed as query parameters, not verbs in URLs.
For example, to filter users by status, use GET /users?status=active instead of /getActiveUsers. This keeps the URL noun-based and uses parameters to specify details.
Result
APIs remain clean and flexible while supporting complex queries.
Knowing how to use query parameters preserves noun-only URLs and avoids verb clutter.
5
IntermediateHandling Complex Actions with Sub-resources
🤔Before reading on: do you think complex actions should be verbs in URLs or modeled differently? Commit to your answer.
Concept: Complex actions can be modeled as sub-resources or state changes, not verbs in URLs.
For example, to activate a user, use POST /users/123/activation instead of /activateUser. This treats activation as a resource representing the activation state.
Result
APIs stay RESTful and expressive without breaking noun-only URL rules.
Understanding sub-resources lets you model actions cleanly without verbs in URLs.
6
AdvancedExceptions and Pragmatic Use of Verbs
🤔Before reading on: do you think verbs in URLs are always wrong or sometimes acceptable? Commit to your answer.
Concept: In some cases, verbs in URLs are pragmatic for non-CRUD actions or RPC-style APIs.
For example, /login or /logout are verbs but often used because they represent operations not fitting resource models. However, these should be exceptions, not the norm.
Result
You learn when to bend rules for practical reasons without losing API clarity.
Knowing when verbs are acceptable prevents dogmatic design and supports real-world API needs.
7
ExpertImpact on API Evolution and Tooling
🤔Before reading on: do you think verb-free URLs affect API versioning and tooling positively or negatively? Commit to your answer.
Concept: Verb-free URLs improve API evolution, caching, and tooling support by keeping resource identity stable and actions separate.
Tools like API gateways, caches, and documentation generators rely on consistent resource URLs. Verb-free URLs make these tools more effective and reduce breaking changes during API updates.
Result
APIs become easier to maintain, scale, and integrate with other systems.
Understanding this impact helps design APIs that last and work well with modern infrastructure.
Under the Hood
When a client sends a request, the server uses the URL to identify the resource and the HTTP method to determine the action. The server routes the request to the correct handler based on this separation. This design allows caching GET requests by URL and simplifies permission checks by resource.
Why designed this way?
REST was designed to separate resource identification from actions to improve scalability, simplicity, and uniformity. Early web architecture inspired this by treating URLs as resource locators and HTTP methods as verbs. Alternatives mixing verbs in URLs led to inconsistent APIs and harder maintenance.
┌───────────────┐       ┌───────────────┐       ┌───────────────┐
│   Client      │──────▶│   Server      │──────▶│ Resource Logic│
│ (URL + Method)│       │ (Router)      │       │ (CRUD actions)│
└───────────────┘       └───────────────┘       └───────────────┘

URL identifies resource → HTTP method defines action → Server executes logic
Myth Busters - 4 Common Misconceptions
Quick: Do you think verbs in URLs make APIs more intuitive? Commit yes or no.
Common Belief:Including verbs in URLs makes the API's purpose clearer because the action is explicit.
Tap to reveal reality
Reality:Verbs in URLs duplicate the meaning of HTTP methods, causing confusion and inconsistency.
Why it matters:This misconception leads to messy APIs that are harder to learn and maintain.
Quick: Do you think URLs should always be verbs to describe actions? Commit yes or no.
Common Belief:URLs should describe what the API does, so verbs belong in URLs.
Tap to reveal reality
Reality:URLs should identify resources; actions belong in HTTP methods or request bodies.
Why it matters:Mixing actions into URLs breaks REST principles and complicates client-server communication.
Quick: Do you think query parameters are for actions or filters? Commit your answer.
Common Belief:Query parameters are just for filtering data, not for specifying actions.
Tap to reveal reality
Reality:Query parameters can specify details of actions without adding verbs to URLs.
Why it matters:Misusing query parameters limits API flexibility and leads to verb-like URLs.
Quick: Do you think exceptions like /login break REST design badly? Commit yes or no.
Common Belief:Any verb in a URL breaks REST and should be avoided at all costs.
Tap to reveal reality
Reality:Some verbs are pragmatic exceptions for operations that don't fit resource models.
Why it matters:Ignoring exceptions can lead to awkward or overly complex API designs.
Expert Zone
1
Some actions are better modeled as state changes on sub-resources rather than verbs, improving clarity and caching.
2
Verb-free URLs improve HTTP caching effectiveness because URLs uniquely identify resources without action ambiguity.
3
API documentation and client code generation tools rely on noun-based URLs to generate consistent interfaces.
When NOT to use
Avoid strict noun-only URLs when implementing RPC-style APIs or operations like authentication where verbs like /login are clearer. In such cases, use clear documentation and consistent patterns to avoid confusion.
Production Patterns
In production, APIs use noun-based URLs with HTTP methods for CRUD operations, sub-resources for complex actions, and query parameters for filtering. Exceptions like /login are isolated and well-documented. This pattern supports scalability, caching, and client compatibility.
Connections
HTTP Methods
Builds-on
Understanding HTTP methods is essential because they carry the action meaning that URLs avoid expressing with verbs.
REST API Design
Core principle
Avoiding verbs in URLs is a fundamental REST design principle that ensures APIs are uniform and scalable.
Library Cataloging Systems
Analogous pattern
Like library catalogs that list books by title (nouns) and separate borrowing actions, URLs name resources while HTTP methods handle actions.
Common Pitfalls
#1Using verbs in URLs causing redundancy and confusion.
Wrong approach:POST /createUser with body {name: 'Alice'}
Correct approach:POST /users with body {name: 'Alice'}
Root cause:Misunderstanding that HTTP methods already express actions, so verbs in URLs are unnecessary.
#2Trying to encode complex actions as verbs in URLs instead of resources.
Wrong approach:POST /activateUser/123
Correct approach:POST /users/123/activation
Root cause:Not modeling actions as sub-resources leads to verb misuse in URLs.
#3Using query parameters as verbs instead of filters.
Wrong approach:GET /users?action=delete&id=123
Correct approach:DELETE /users/123
Root cause:Confusing query parameters as action triggers rather than filters or modifiers.
Key Takeaways
URLs should name resources using nouns, while HTTP methods specify actions on those resources.
Avoiding verbs in URLs keeps APIs consistent, predictable, and easier to maintain.
Complex actions can be modeled as sub-resources or state changes instead of verbs in URLs.
Some pragmatic exceptions exist, but they should be limited and well-documented.
This design improves caching, tooling support, and API evolution over time.

Practice

(1/5)
1. Which of the following URLs follows the best practice of avoiding verbs in REST API design?
easy
A. /createUser
B. /getUser/123
C. /deleteUser/123
D. /users/123

Solution

  1. Step 1: Understand URL naming conventions

    REST APIs should use nouns to represent resources, not verbs. URLs like /users/123 represent a user resource with ID 123.
  2. Step 2: Identify verbs in URLs

    URLs like /getUser/123, /createUser, and /deleteUser/123 contain verbs (get, create, delete), which is against best practice.
  3. Final Answer:

    /users/123 -> Option D
  4. Quick Check:

    Use nouns in URLs = /users/123 [OK]
Hint: Use nouns for URLs, verbs go in HTTP methods [OK]
Common Mistakes:
  • Including verbs like 'get' or 'delete' in the URL
  • Using action words instead of resource names
  • Confusing HTTP methods with URL paths
2. Which HTTP method should be used with the URL /orders/456 to update an existing order?
easy
A. PUT
B. POST
C. DELETE
D. GET

Solution

  1. Step 1: Match HTTP methods to actions

    GET retrieves data, POST creates new data, PUT updates existing data, DELETE removes data.
  2. Step 2: Identify update action

    To update an existing order at /orders/456, the correct HTTP method is PUT.
  3. Final Answer:

    PUT -> Option A
  4. Quick Check:

    Update = PUT [OK]
Hint: PUT updates, POST creates, GET reads, DELETE removes [OK]
Common Mistakes:
  • Using POST to update instead of create
  • Using GET to modify data
  • Confusing PUT and DELETE methods
3. Given the REST API call: DELETE /products/789, what is the expected action?
medium
A. Delete product with ID 789
B. Create a new product with ID 789
C. Retrieve product with ID 789
D. Update product with ID 789

Solution

  1. Step 1: Understand HTTP DELETE method

    DELETE is used to remove a resource identified by the URL.
  2. Step 2: Apply to given URL

    The URL /products/789 identifies product 789, so DELETE removes it.
  3. Final Answer:

    Delete product with ID 789 -> Option A
  4. Quick Check:

    DELETE removes resource = Delete product with ID 789 [OK]
Hint: DELETE method removes resource at URL [OK]
Common Mistakes:
  • Thinking DELETE retrieves data
  • Confusing DELETE with POST or PUT
  • Assuming URL contains action verbs
4. Identify the error in this REST API design: POST /updateUser/123
medium
A. User ID should not be in the URL
B. HTTP method POST cannot be used with user resources
C. URL contains a verb 'update', which should be avoided
D. URL should end with a question mark

Solution

  1. Step 1: Check URL naming conventions

    URLs should use nouns to represent resources, not verbs like 'update'. The verb should be expressed by the HTTP method.
  2. Step 2: Analyze the given URL

    The URL /updateUser/123 contains the verb 'update', which violates REST best practices.
  3. Final Answer:

    URL contains a verb 'update', which should be avoided -> Option C
  4. Quick Check:

    Verbs in URL = URL contains a verb 'update', which should be avoided [OK]
Hint: Avoid verbs in URLs; use HTTP methods for actions [OK]
Common Mistakes:
  • Putting verbs like 'update' in URLs
  • Misusing HTTP methods
  • Ignoring resource identification in URLs
5. You want to design a REST API to manage blog posts. Which URL and HTTP method combination correctly avoids verbs in the URL and uses HTTP methods properly to delete a post with ID 321?
hard
A. DELETE /deletePost/321
B. DELETE /posts/321
C. POST /posts/321/delete
D. GET /posts/delete/321

Solution

  1. Step 1: Identify correct URL structure

    The URL should use a noun representing the resource, here /posts/321, without verbs like 'delete'.
  2. Step 2: Match HTTP method to action

    To delete a resource, use the DELETE method with the resource URL.
  3. Final Answer:

    DELETE /posts/321 -> Option B
  4. Quick Check:

    Delete resource = DELETE + noun URL [OK]
Hint: Use DELETE method with noun URL to remove resource [OK]
Common Mistakes:
  • Including verbs like 'delete' in the URL
  • Using GET or POST for delete actions
  • Placing action words after resource ID
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard