0
0
Rest APIprogramming~10 mins

Last-Modified and If-Modified-Since 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 set the Last-Modified header in the HTTP response.

Rest API
response.headers['Last-Modified'] = [1]
Drag options to blanks, or click blank then click option'
A'If-Modified-Since'
B'Wed, 21 Oct 2015 07:28:00 GMT'
C'200 OK'
D'Content-Type'
Attempts:
3 left
💡 Hint
Common Mistakes
Using header names instead of date strings.
Setting unrelated header values.
2fill in blank
medium

Complete the code to read the If-Modified-Since header from the HTTP request.

Rest API
last_seen = request.headers.get([1])
Drag options to blanks, or click blank then click option'
A'Authorization'
B'Last-Modified'
C'Content-Length'
D'If-Modified-Since'
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing with Last-Modified header.
Using unrelated headers.
3fill in blank
hard

Fix the error in the code that compares If-Modified-Since with Last-Modified to decide if the resource is modified.

Rest API
if last_modified <= [1]:
    return 304
Drag options to blanks, or click blank then click option'
Alast_seen
Brequest.headers['If-Modified-Since']
CNone
Dresponse.headers['Last-Modified']
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing header strings directly without parsing.
Using wrong variables.
4fill in blank
hard

Fill both blanks to parse the If-Modified-Since header and compare it with the last modified time.

Rest API
from datetime import datetime

client_time = datetime.strptime([1], '%a, %d %b %Y %H:%M:%S GMT')
if last_modified <= [2]:
    return 304
Drag options to blanks, or click blank then click option'
Alast_seen
Brequest.headers.get('If-Modified-Since')
Cclient_time
Dresponse.headers['Last-Modified']
Attempts:
3 left
💡 Hint
Common Mistakes
Parsing the wrong header.
Comparing string with datetime.
5fill in blank
hard

Fill all three blanks to set Last-Modified header, parse If-Modified-Since, and return 304 if not modified.

Rest API
from datetime import datetime

last_modified = datetime(2023, 6, 1, 12, 0, 0)
response.headers['Last-Modified'] = [1]
client_header = request.headers.get('If-Modified-Since')
client_time = datetime.strptime([2], '%a, %d %b %Y %H:%M:%S GMT') if client_header else None
if client_time and last_modified <= [3]:
    return 304
Drag options to blanks, or click blank then click option'
A'Thu, 01 Jun 2023 12:00:00 GMT'
Bclient_header
Cclient_time
D'Wed, 21 Oct 2015 07:28:00 GMT'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong date strings.
Not checking if client_header exists.
Comparing string with datetime.