0
0
Rest APIprogramming~3 mins

Why Avoiding verbs in URLs in Rest API? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if your URLs could speak clearly without shouting commands?

The Scenario

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.

The Problem

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.

The Solution

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.

Before vs After
Before
POST /createTask
GET /deleteTask?id=123
After
POST /tasks
DELETE /tasks/123
What It Enables

This approach enables clean, predictable URLs that work naturally with web standards and make your API easy to use and scale.

Real Life Example

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.

Key Takeaways

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.