0
0
Rest APIprogramming~10 mins

Idempotency keys for safe retries 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 add an idempotency key header to the API request.

Rest API
headers = {"Content-Type": "application/json", "[1]": "12345-abcde"}
Drag options to blanks, or click blank then click option'
AAccept
BAuthorization
CIdempotency-Key
DUser-Agent
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Authorization' instead of 'Idempotency-Key'.
Forgetting to add the idempotency key header.
2fill in blank
medium

Complete the code to check if the idempotency key already exists in the server's storage.

Rest API
if [1] in stored_keys:
    return stored_keys[[1]]
Drag options to blanks, or click blank then click option'
Arequest.body
Brequest.headers.get('Idempotency-Key')
Crequest.method
Drequest.url
Attempts:
3 left
💡 Hint
Common Mistakes
Checking the request body instead of headers.
Using the URL or method instead of the idempotency key.
3fill in blank
hard

Fix the error in the code that stores the response using the idempotency key.

Rest API
stored_keys[[1]] = response
Drag options to blanks, or click blank then click option'
Arequest.headers.get('Idempotency-Key')
Brequest.body
Cresponse.status_code
Drequest.url
Attempts:
3 left
💡 Hint
Common Mistakes
Using request body or URL as the key instead of the idempotency key.
Storing the status code instead of the full response.
4fill in blank
hard

Fill both blanks to safely retry a POST request using idempotency key logic.

Rest API
key = request.headers.get('[1]')
if key and key [2] stored_keys:
    return stored_keys[key]
Drag options to blanks, or click blank then click option'
AIdempotency-Key
Bnot in
Cin
DAuthorization
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'not in' instead of 'in' for the check.
Using wrong header names like 'Authorization'.
5fill in blank
hard

Fill all three blanks to implement idempotency key storage and response retrieval.

Rest API
key = request.headers.get('[1]')
if key [2] stored_keys:
    return stored_keys[key]
response = process_request(request)
stored_keys[[3]] = response
Drag options to blanks, or click blank then click option'
AIdempotency-Key
Bin
Ckey
DAuthorization
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Authorization' instead of 'Idempotency-Key'.
Using 'not in' instead of 'in' for the check.
Storing response with wrong dictionary key.