0
0
Rest APIprogramming~10 mins

API analytics and usage metrics in Rest API - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to retrieve the total number of API requests from the analytics endpoint.

Rest API
response = requests.get('https://api.example.com/analytics/usage')
total_requests = response.json().get([1])
Drag options to blanks, or click blank then click option'
ArequestCount
BtotalRequests
Ctotal_calls
DusageCount
Attempts:
3 left
💡 Hint
Common Mistakes
Using a key that does not exist in the response JSON.
Confusing total requests with usage count.
2fill in blank
medium

Complete the code to filter API usage data for the last 7 days using query parameters.

Rest API
params = {'period': [1]
response = requests.get('https://api.example.com/analytics/usage', params=params)
Drag options to blanks, or click blank then click option'
A'last_month'
B'weekly'
C'last_7_days'
D'7days'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect period strings like 'weekly' or '7days' which the API does not recognize.
Omitting quotes around the string value.
3fill in blank
hard

Fix the error in the code to correctly parse the JSON response and extract the average response time.

Rest API
data = response.[1]()
avg_response_time = data['metrics']['avgResponseTime']
Drag options to blanks, or click blank then click option'
Aparse_json
Btext
Ccontent
Djson
Attempts:
3 left
💡 Hint
Common Mistakes
Using text() which returns a string, not a dictionary.
Trying to access JSON data without parsing it first.
4fill in blank
hard

Complete the code to create a dictionary comprehension that maps each API endpoint to its total call count, filtering only endpoints with more than 100 calls.

Rest API
endpoint_calls = {endpoint: data[endpoint] for endpoint in data if data[endpoint] [1] 100}
Drag options to blanks, or click blank then click option'
B>
C>=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Adding an operator after data[endpoint] in the value part causing syntax errors.
Using less than operator which filters wrong endpoints.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each API endpoint (in uppercase) to its average response time, including only endpoints with average response time less than 200 ms.

Rest API
fast_endpoints = [1]: data[endpoint]['avgResponseTime'] for endpoint in data if data[endpoint]['avgResponseTime'] [2] [3]
Drag options to blanks, or click blank then click option'
Aendpoint.upper()
B<
C200
Dendpoint.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase instead of uppercase for keys.
Using greater than operator which filters wrong endpoints.
Omitting the threshold value.