What if your API could speak a simple, universal language everyone understands instantly?
Why Noun-based resource naming in Rest API? - Purpose & Use Cases
Imagine you are building a website where users can manage books, authors, and orders. You try to name your API endpoints using verbs like /getBooks, /createAuthor, or /deleteOrder. As your project grows, it becomes confusing to remember which verbs to use and how to combine them.
Using verbs in URLs makes your API inconsistent and hard to maintain. You have to remember many different action words, and it's easy to make mistakes or misunderstand what each endpoint does. This slows down development and causes bugs.
Noun-based resource naming uses simple, clear nouns to represent things in your system, like /books, /authors, and /orders. Actions like getting, creating, or deleting are handled by HTTP methods (GET, POST, DELETE). This makes your API easy to understand and consistent.
/getBooks /createAuthor /deleteOrder
GET /books
POST /authors
DELETE /orders/{id}This approach lets developers quickly understand and use your API without guessing, making teamwork and scaling much easier.
Think of an online store API where you can list products with GET /products, add a new product with POST /products, or remove a product with DELETE /products/{id}. It's clear and simple for everyone.
Using nouns for resource names keeps APIs simple and consistent.
HTTP methods handle actions, so URLs stay clean and easy to remember.
This makes APIs easier to use, maintain, and scale.
Practice
Solution
Step 1: Understand noun-based resource naming
Noun-based naming uses plural nouns to represent collections of resources, making the API intuitive.Step 2: Identify the correct plural noun path
Among the options, only '/books' is a plural noun representing the resource collection without verbs or actions.Final Answer:
/books -> Option DQuick Check:
Noun-based resource = /books [OK]
- Including verbs like 'get' or 'fetch' in the URL
- Using singular nouns for collections
- Adding action words in resource names
Solution
Step 1: Review REST API syntax for single resource
Single resources are accessed by appending the resource ID to the plural noun path.Step 2: Identify the correct syntax
Option '/users/123' correctly uses the plural noun 'users' followed by the ID without verbs or query parameters.Final Answer:
/users/123 -> Option CQuick Check:
Single resource path = /users/123 [OK]
- Adding verbs like 'get' in the path
- Using query parameters instead of path variables
- Using singular noun without ID
GET /orders/456, what does this request represent?Solution
Step 1: Understand HTTP GET method
GET is used to retrieve or read data from the server without modifying it.Step 2: Interpret the endpoint path
The path '/orders/456' points to a single order resource with ID 456.Final Answer:
Retrieve the order with ID 456 -> Option AQuick Check:
GET /orders/456 = Retrieve order 456 [OK]
- Confusing GET with POST or DELETE actions
- Assuming the request modifies data
- Misreading the resource ID
DELETE /deleteUser/789Solution
Step 1: Check resource naming conventions
Resource paths should be nouns, not verbs or actions.Step 2: Analyze the given endpoint
The path '/deleteUser/789' incorrectly includes the verb 'deleteUser' instead of just '/users/789'.Final Answer:
Using a verb 'deleteUser' in the resource path -> Option BQuick Check:
Resource path must be noun, not verb [OK]
- Including action verbs in URL paths
- Confusing HTTP method with URL naming
- Using query parameters unnecessarily
Solution
Step 1: Understand nested resource naming
Comments belong to posts, so nesting comments under posts is clear and RESTful.Step 2: Evaluate the options
Option '/posts/42/comments' uses plural nouns and shows the relationship clearly without verbs or query parameters.Final Answer:
/posts/42/comments -> Option AQuick Check:
Nested plural nouns show resource hierarchy [OK]
- Using verbs in paths like 'getCommentsForPost'
- Using query parameters instead of nested paths
- Using singular nouns inconsistently
Ready to prove it?
Pass the test and this pattern moves unknown
