0
0
Rest APIprogramming~10 mins

Last-Modified and If-Modified-Since in Rest API - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Last-Modified and If-Modified-Since
Client sends GET request
Server checks resource last modified date
Does client send If-Modified-Since header?
NoSend full resource with 200 OK
Yes
Compare If-Modified-Since date with resource last modified
End
The client sends a GET request. The server checks if the client sent an If-Modified-Since date. If yes, it compares with the resource's last modified date. If the resource is unchanged, server replies 304 Not Modified. Otherwise, it sends the full resource with 200 OK.
Execution Sample
Rest API
GET /image.png HTTP/1.1
Host: example.com
If-Modified-Since: Wed, 21 Oct 2020 07:28:00 GMT

Server response:
HTTP/1.1 304 Not Modified

(no body)
Client requests an image with If-Modified-Since header. Server replies 304 Not Modified if image unchanged since that date.
Execution Table
StepClient RequestServer ActionConditionServer Response
1GET /image.png (no If-Modified-Since)Check resource last modified dateNo If-Modified-Since header200 OK with full image
2GET /image.png with If-Modified-Since: 2020-10-21T07:28:00ZCompare If-Modified-Since with resource last modifiedResource last modified 2020-10-20T10:00:00Z < If-Modified-Since304 Not Modified, no body
3GET /image.png with If-Modified-Since: 2020-10-21T07:28:00ZCompare If-Modified-Since with resource last modifiedResource last modified 2020-10-22T09:00:00Z > If-Modified-Since200 OK with full image
4EndNo further actionRequest handledConnection closed
💡 Execution stops after server sends response based on resource modification check.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
If-Modified-Since headerNoneNoneWed, 21 Oct 2020 07:28:00 GMTWed, 21 Oct 2020 07:28:00 GMTWed, 21 Oct 2020 07:28:00 GMT
Resource Last-Modified2020-10-20T10:00:00Z2020-10-20T10:00:00Z2020-10-20T10:00:00Z2020-10-22T09:00:00Z2020-10-22T09:00:00Z
Server ResponseNone200 OK with full image304 Not Modified200 OK with full image200 OK with full image or 304 Not Modified
Key Moments - 3 Insights
Why does the server send a 304 Not Modified response instead of the full resource?
Because the If-Modified-Since date sent by the client is later than the resource's last modified date, meaning the client already has the latest version. See execution_table row 2.
What happens if the client does not send the If-Modified-Since header?
The server sends the full resource with a 200 OK response because it has no information to check if the client has a fresh copy. See execution_table row 1.
If the resource was modified after the If-Modified-Since date, what response does the server send?
The server sends the full resource with a 200 OK response to update the client. See execution_table row 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table row 2. What is the server's response when the resource last modified date is before the If-Modified-Since date?
A404 Not Found
B304 Not Modified with no body
C200 OK with full resource
D500 Internal Server Error
💡 Hint
Check the 'Server Response' column in row 2 of the execution_table.
According to variable_tracker, what is the value of 'If-Modified-Since header' after step 1?
ANone
BWed, 21 Oct 2020 07:28:00 GMT
C2020-10-20T10:00:00Z
D2020-10-22T09:00:00Z
💡 Hint
Look at the 'If-Modified-Since header' row and the 'After Step 1' column in variable_tracker.
If the resource last modified date changes to a date after the If-Modified-Since date, how does the server response change?
AIt sends 304 Not Modified
BIt sends 404 Not Found
CIt sends 200 OK with full resource
DIt sends 500 Internal Server Error
💡 Hint
Refer to execution_table row 3 where resource last modified is after If-Modified-Since.
Concept Snapshot
Last-Modified and If-Modified-Since headers help cache validation.
Client sends If-Modified-Since with a date.
Server compares with resource's Last-Modified date.
If resource unchanged, server replies 304 Not Modified (no body).
If changed, server replies 200 OK with full resource.
This saves bandwidth and speeds up loading.
Full Transcript
This visual trace shows how the Last-Modified and If-Modified-Since headers work in HTTP caching. The client sends a GET request optionally with an If-Modified-Since header containing a date. The server checks the resource's last modified date. If the client did not send If-Modified-Since, the server sends the full resource with 200 OK. If the client sent If-Modified-Since, the server compares it with the resource's last modified date. If the resource has not changed since that date, the server sends a 304 Not Modified response with no body, telling the client to use its cached copy. If the resource has changed, the server sends the full resource with 200 OK. The execution table shows different scenarios and server responses. The variable tracker shows how the headers and dates change during the process. Key moments clarify common confusions about when 304 is sent and what happens without If-Modified-Since. The quiz tests understanding of these steps. This mechanism helps reduce data transfer and speeds up web browsing by avoiding unnecessary downloads.