0
0
Rest APIprogramming~20 mins

API analytics and usage metrics in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
API Analytics Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
API Request Count Calculation
Given the following API usage log data, what is the total number of requests made to the API?
Rest API
api_logs = [
  {"endpoint": "/users", "method": "GET"},
  {"endpoint": "/users", "method": "POST"},
  {"endpoint": "/orders", "method": "GET"},
  {"endpoint": "/users", "method": "GET"},
  {"endpoint": "/orders", "method": "POST"}
]
total_requests = len(api_logs)
print(total_requests)
A5
B2
C4
D3
Attempts:
2 left
💡 Hint
Count each dictionary entry as one request.
🧠 Conceptual
intermediate
1:30remaining
Understanding API Rate Limiting
Which of the following best describes the purpose of API rate limiting?
ATo cache API responses for faster access
BTo encrypt API data for secure transmission
CTo log all API errors for debugging
DTo restrict the number of API calls a client can make in a given time to prevent overload
Attempts:
2 left
💡 Hint
Think about controlling traffic to the API.
Predict Output
advanced
2:00remaining
Calculating Average Response Time
What is the output of the following code that calculates the average response time from API metrics?
Rest API
response_times = [120, 150, 100, 130, 110]
avg_response_time = sum(response_times) / len(response_times)
print(round(avg_response_time))
A122.0
B122.5
C122
D121
Attempts:
2 left
💡 Hint
Sum all times and divide by count, then round to nearest integer.
🔧 Debug
advanced
2:30remaining
Identify the Error in API Usage Data Aggregation
What error will the following code raise when trying to aggregate API calls by endpoint?
Rest API
api_calls = [
  {"endpoint": "/login", "count": 10},
  {"endpoint": "/logout", "count": 5},
  {"endpoint": "/login", "count": 7}
]

aggregated = {}
for call in api_calls:
    aggregated[call["endpoint"]] += call["count"]
print(aggregated)
AKeyError
BTypeError
CSyntaxError
DNo error, outputs {'/login': 17, '/logout': 5}
Attempts:
2 left
💡 Hint
Check if dictionary keys exist before adding.
🚀 Application
expert
3:00remaining
Determine the Number of Unique API Users
Given the following API usage data, how many unique users accessed the API?
Rest API
api_usage = [
  {"user_id": "u1", "endpoint": "/data"},
  {"user_id": "u2", "endpoint": "/data"},
  {"user_id": "u1", "endpoint": "/status"},
  {"user_id": "u3", "endpoint": "/data"},
  {"user_id": "u2", "endpoint": "/status"}
]
unique_users = len(set(entry["user_id"] for entry in api_usage))
print(unique_users)
A2
B3
C5
D4
Attempts:
2 left
💡 Hint
Count distinct user_id values.