0
0
Rest APIprogramming~30 mins

API analytics and usage metrics in Rest API - Mini Project: Build & Apply

Choose your learning style9 modes available
API Analytics and Usage Metrics
📖 Scenario: You work for a company that provides a public API. Your job is to analyze the usage data to understand how many times each API endpoint was called and by which users.
🎯 Goal: Build a simple program that processes API call logs stored in a dictionary, counts the number of calls per endpoint, and shows usage metrics per user.
📋 What You'll Learn
Create a dictionary with API call logs
Add a variable to hold a threshold for minimum calls
Use a loop to count calls per endpoint and per user
Print the final usage metrics
💡 Why This Matters
🌍 Real World
API providers often need to analyze usage data to improve performance and detect abuse.
💼 Career
Understanding API analytics is important for backend developers, data analysts, and product managers.
Progress0 / 4 steps
1
Create API call logs dictionary
Create a dictionary called api_calls with these exact entries: 'user1': ['/login', '/data', '/logout'], 'user2': ['/login', '/data', '/data'], 'user3': ['/login', '/logout']
Rest API
Need a hint?

Use curly braces to create a dictionary. Keys are user names, values are lists of API endpoints called.

2
Add minimum call threshold
Create a variable called min_calls and set it to 2 to filter endpoints with at least 2 calls
Rest API
Need a hint?

Just create a variable and assign the number 2 to it.

3
Count calls per endpoint and per user
Create two empty dictionaries called endpoint_counts and user_counts. Then use a for loop with variables user and calls to iterate over api_calls.items(). Inside, use another for loop with variable endpoint to iterate over calls. Increment counts in both dictionaries accordingly.
Rest API
Need a hint?

Use dict.get(key, 0) to safely increment counts. Remember to count total calls per user and per endpoint.

4
Print usage metrics filtered by threshold
Use a for loop with variables endpoint and count to iterate over endpoint_counts.items(). Inside the loop, use an if statement to check if count is greater than or equal to min_calls. If yes, print the message f"Endpoint {endpoint} was called {count} times". Then print the user_counts dictionary.
Rest API
Need a hint?

Use a loop and an if condition to filter and print. Then print the user_counts dictionary as is.