0
0
Rest APIprogramming~5 mins

Why hypermedia drives discoverability in Rest API - Performance Analysis

Choose your learning style9 modes available
Time Complexity: Why hypermedia drives discoverability
O(n)
Understanding Time Complexity

When working with hypermedia in REST APIs, it's important to understand how the number of operations grows as clients discover new links dynamically.

We want to see how the process of following links affects the total work done by the client.

Scenario Under Consideration

Analyze the time complexity of this simplified hypermedia client code.


function fetchResources(url) {
  fetch(url).then(response => response.json()).then(data => {
    data.links.forEach(link => {
      fetchResources(link.href);
    });
  });
}

fetchResources('https://api.example.com/root');
    

This code fetches a resource, then recursively fetches all linked resources it finds.

Identify Repeating Operations

Look at what repeats as the client discovers new links.

  • Primary operation: Fetching each resource and iterating over its links.
  • How many times: Once per resource discovered, potentially many times as links lead to more resources.
How Execution Grows With Input

As the number of linked resources grows, the client fetches more and more resources.

Input Size (number of resources)Approx. Operations (fetches)
10About 10 fetch calls
100About 100 fetch calls
1000About 1000 fetch calls

Pattern observation: The number of fetches grows roughly in direct proportion to the number of resources linked.

Final Time Complexity

Time Complexity: O(n)

This means the total work grows linearly with the number of resources discovered through links.

Common Mistake

[X] Wrong: "Following links in hypermedia is free or constant time because each fetch is independent."

[OK] Correct: Each link leads to a new fetch, so the total work adds up as more resources are discovered.

Interview Connect

Understanding how hypermedia-driven discovery scales helps you explain API client behavior clearly and shows you grasp how dynamic data affects performance.

Self-Check

What if we limited the number of links followed per resource? How would that change the time complexity?