0
0
Rest APIprogramming~10 mins

If-None-Match and 304 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 check if the client's ETag matches the server's ETag.

Rest API
if request.headers.get('If-None-Match') == [1]:
    return '', 304
Drag options to blanks, or click blank then click option'
Aserver_etag
Bclient_etag
Cetag_value
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using the client's ETag variable instead of the server's ETag for comparison.
Comparing to None instead of the server's ETag.
2fill in blank
medium

Complete the code to set the ETag header in the server's response.

Rest API
response.headers['ETag'] = [1]
Drag options to blanks, or click blank then click option'
Aserver_etag
BNone
Cetag_value
Dclient_etag
Attempts:
3 left
💡 Hint
Common Mistakes
Setting the ETag header to the client's ETag value.
Leaving the ETag header unset.
3fill in blank
hard

Fix the error in the code that returns a 304 response when ETags match.

Rest API
if request.headers.get('If-None-Match') == [1]:
    return '', 304
Drag options to blanks, or click blank then click option'
Aetag_value
Bclient_etag
Cserver_etag
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 200 instead of 304 when ETags match.
Comparing to the wrong ETag variable.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps resource IDs to their ETags only if the ETag length is greater than 10.

Rest API
etag_map = {resource_id: [1] for resource_id, [2] in resources.items() if len(etag) > 10}
Drag options to blanks, or click blank then click option'
Aetag
Betag_value
Dresource_etag
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent variable names for ETag in the comprehension.
Using the wrong variable in the if condition.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase resource IDs to their ETags only if the ETag starts with 'W/'.

Rest API
etag_map = { [1]: [2] for resource_id, etag in resources.items() if etag.[3]('W/') }
Drag options to blanks, or click blank then click option'
Aresource_id.upper()
Betag
Cstartswith
Dendswith
Attempts:
3 left
💡 Hint
Common Mistakes
Using endswith instead of startswith.
Not converting resource IDs to uppercase.