0
0
Rest APIprogramming~5 mins

Noun-based resource naming in Rest API - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Noun-based resource naming
O(n)
Understanding Time 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.

Scenario Under Consideration

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.

Identify Repeating Operations

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.
How Execution Grows With Input

As the number of users or orders grows, the time to find or list them changes.

Input Size (n)Approx. Operations
10 usersAbout 10 checks or reads
100 usersAbout 100 checks or reads
1000 usersAbout 1000 checks or reads

Pattern observation: The time grows roughly in direct proportion to the number of items.

Final Time Complexity

Time Complexity: O(n)

This means the time to handle requests grows linearly with the number of resources.

Common Mistake

[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.

Interview Connect

Understanding how resource naming relates to request handling helps you explain API design clearly and think about performance.

Self-Check

"What if we changed resource names from nouns to verbs? How would the time complexity of handling requests change?"