Complete the code to retrieve the total number of API requests from the analytics endpoint.
response = requests.get('https://api.example.com/analytics/usage') total_requests = response.json().get([1])
The key requestCount holds the total number of API requests in the JSON response.
Complete the code to filter API usage data for the last 7 days using query parameters.
params = {'period': [1]
response = requests.get('https://api.example.com/analytics/usage', params=params)The API expects the period parameter as 'last_7_days' to filter data for the last week.
Fix the error in the code to correctly parse the JSON response and extract the average response time.
data = response.[1]() avg_response_time = data['metrics']['avgResponseTime']
text() which returns a string, not a dictionary.The json() method parses the response body as JSON, allowing access to nested data.
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.
endpoint_calls = {endpoint: data[endpoint] for endpoint in data if data[endpoint] [1] 100}The comprehension maps each endpoint to its call count directly (no operator needed after data[endpoint]) and filters endpoints with calls greater than 100.
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.
fast_endpoints = [1]: data[endpoint]['avgResponseTime'] for endpoint in data if data[endpoint]['avgResponseTime'] [2] [3]
The comprehension uses endpoint.upper() as the key, filters average response times less than 200 ms using < and 200 as the threshold.