What if your URLs could speak clearly without shouting commands?
Why Avoiding verbs in URLs in Rest API? - Purpose & Use Cases
Imagine you are building a website where users can manage their tasks. You decide to name your web addresses like /createTask or /deleteTask to perform actions.
This approach quickly becomes confusing and inconsistent. It mixes actions with resource names, making URLs hard to remember and maintain. Also, it breaks the natural way web browsers and servers expect URLs to work.
By avoiding verbs in URLs and focusing on nouns (resources), you create clear, consistent addresses like /tasks. Actions are then handled by HTTP methods like GET, POST, DELETE, making your API easier to understand and use.
POST /createTask
GET /deleteTask?id=123POST /tasks
DELETE /tasks/123This approach enables clean, predictable URLs that work naturally with web standards and make your API easy to use and scale.
Think of an online store: instead of /buyProduct, you use /products with POST to add to cart, and DELETE to remove items, making the system intuitive and consistent.
Manual URLs with verbs mix actions and resources, causing confusion.
Using nouns in URLs and HTTP methods for actions keeps APIs clean.
This leads to easier maintenance and better user experience.