Noun-based resource naming in Rest API - Time & Space Complexity
When designing REST APIs, using noun-based resource names helps organize data access clearly.
We want to see how the number of operations grows when accessing resources named as nouns.
Analyze the time complexity of the following REST API endpoint handling.
GET /users
GET /users/{id}
POST /users
GET /users/{id}/orders
This code snippet shows typical noun-based resource paths for users and their orders.
Look at what repeats when the API handles requests.
- Primary operation: Searching or retrieving user or order data from storage.
- How many times: Once per request, but the data size affects how long it takes.
As the number of users or orders grows, the time to find or list them changes.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 users | About 10 checks or reads |
| 100 users | About 100 checks or reads |
| 1000 users | About 1000 checks or reads |
Pattern observation: The time grows roughly in direct proportion to the number of items.
Time Complexity: O(n)
This means the time to handle requests grows linearly with the number of resources.
[X] Wrong: "Naming resources as nouns makes the API faster."
[OK] Correct: The naming style organizes the API but does not change how fast data is found or processed.
Understanding how resource naming relates to request handling helps you explain API design clearly and think about performance.
"What if we changed resource names from nouns to verbs? How would the time complexity of handling requests change?"