0
0
Rest APIprogramming~10 mins

Long-running operations (async responses) 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 start an asynchronous operation by sending a POST request.

Rest API
response = requests.post('[1]/start-operation')
Drag options to blanks, or click blank then click option'
Afile://api.example.com
Bftp://api.example.com
Csmtp://api.example.com
Dhttp://api.example.com
Attempts:
3 left
💡 Hint
Common Mistakes
Using unsupported URL schemes like ftp or file.
Forgetting to include the protocol in the URL.
2fill in blank
medium

Complete the code to check if the operation status is 'completed'.

Rest API
if status == '[1]':
Drag options to blanks, or click blank then click option'
Acompleted
Bstarted
Cfailed
Dpending
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 'pending' or 'started' which mean the operation is not done.
Using incorrect status strings.
3fill in blank
hard

Fix the error in the code to correctly poll the operation status until it is completed.

Rest API
while status != '[1]':
    time.sleep(5)
    status = get_status(operation_id)
Drag options to blanks, or click blank then click option'
Aerror
Bpending
Ccompleted
Dcancelled
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'pending' or 'error' as the stop condition.
Not updating the status inside the loop.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps operation IDs to their statuses only if the status is 'completed'.

Rest API
completed_ops = {op_id: [1] for op_id, [2] in operations.items() if status == 'completed'}
Drag options to blanks, or click blank then click option'
Astatus
Cresult
Dstate
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect variable names like 'result' or 'state'.
Not matching the variable names in the comprehension.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase operation IDs to their results only if the result is greater than 0.

Rest API
filtered_results = { [1]: [2] for op_id, [3] in results.items() if [2] > 0 }
Drag options to blanks, or click blank then click option'
Aop_id.upper()
Bresult
Dop_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using the original operation ID instead of uppercase.
Mixing variable names in unpacking and value.