0
0
Rest APIprogramming~10 mins

Avoiding verbs in URLs in Rest API - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Avoiding verbs in URLs
Client sends HTTP request
URL contains noun (resource)
HTTP method defines action
Server processes request
Response sent back to client
The client sends a request with a URL that names the resource (noun). The HTTP method (GET, POST, etc.) tells what action to do. The server uses this to respond.
Execution Sample
Rest API
GET /books
POST /books
PUT /books/123
DELETE /books/123
These URLs use nouns (books) and HTTP methods to specify actions without verbs in the URL.
Execution Table
StepHTTP MethodURLAction Defined ByResourceVerb in URL?
1GET/booksHTTP Method (GET)booksNo
2POST/booksHTTP Method (POST)booksNo
3PUT/books/123HTTP Method (PUT)books/123No
4DELETE/books/123HTTP Method (DELETE)books/123No
5GET/getBooksURL contains verb 'get'getBooksYes
💡 Step 5 shows a URL with a verb, which is discouraged; steps 1-4 follow best practice.
Variable Tracker
VariableStep 1Step 2Step 3Step 4Step 5
HTTP MethodGETPOSTPUTDELETEGET
URL/books/books/books/123/books/123/getBooks
Action SourceMethodMethodMethodMethodURL verb
Verb in URL?NoNoNoNoYes
Key Moments - 2 Insights
Why should we avoid verbs in URLs?
Because HTTP methods already define actions, adding verbs in URLs is redundant and can confuse clients and servers. See execution_table step 5 where the URL has a verb.
How do we know what action to perform if URLs don't have verbs?
The HTTP method (GET, POST, PUT, DELETE) tells the server what action to do. Look at execution_table steps 1-4 where the method defines the action.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, which step shows a URL with a verb?
AStep 5
BStep 1
CStep 3
DStep 2
💡 Hint
Check the 'Verb in URL?' column in execution_table.
At which step does the HTTP method define the action without a verb in the URL?
AStep 5
BStep 1
CStep 4
DStep 3
💡 Hint
Look at steps where 'Verb in URL?' is 'No' and action is from HTTP method.
If we changed step 5 URL to '/books', what would change in the 'Verb in URL?' column?
AIt would stay 'Yes'
BIt would change to 'No'
CIt would be empty
DIt would say 'Maybe'
💡 Hint
Check how URLs without verbs are marked in execution_table.
Concept Snapshot
Avoid verbs in URLs.
Use nouns to name resources (e.g., /books).
Use HTTP methods (GET, POST, PUT, DELETE) to specify actions.
This keeps URLs clean and RESTful.
Example: GET /books fetches books, no verb needed in URL.
Full Transcript
In REST APIs, URLs should name resources using nouns, not verbs. The HTTP method tells the server what action to perform. For example, GET /books fetches books, POST /books adds a book, PUT /books/123 updates book 123, and DELETE /books/123 deletes it. Avoid URLs like /getBooks because the verb 'get' is redundant and breaks REST principles. The execution table shows steps with HTTP methods and URLs without verbs, and one example with a verb in the URL to highlight the difference. Variables track the HTTP method, URL, and whether the URL contains a verb. Key moments clarify why verbs in URLs are avoided and how HTTP methods define actions. The quiz tests understanding of these points. Remember: clean URLs use nouns; HTTP methods do the work.