Consider a REST API endpoint that returns a resource with the header Last-Modified: Wed, 21 Oct 2015 07:28:00 GMT. A client sends a GET request with the header If-Modified-Since: Wed, 21 Oct 2015 07:28:00 GMT. What status code will the server most likely return?
Think about what the If-Modified-Since header asks the server to do.
The If-Modified-Since header tells the server to send the resource only if it has been modified after the specified date. Since the Last-Modified date matches the If-Modified-Since date, the server responds with 304 Not Modified to save bandwidth.
What is the main purpose of the Last-Modified HTTP header in REST APIs?
Think about how clients can avoid downloading unchanged data.
The Last-Modified header tells clients the last time the resource was changed. Clients can use this information in If-Modified-Since requests to avoid downloading data that hasn't changed.
A server resource has Last-Modified: Mon, 01 Jan 2024 10:00:00 GMT. A client sends a GET request with If-Modified-Since: Tue, 02 Jan 2024 10:00:00 GMT. What will the server respond?
Consider if the resource has changed since the date the client provides.
The client asks if the resource has changed since a date later than the resource's last modification. Since the resource was last modified before that date, the server responds with 304 Not Modified, indicating no new changes.
A developer implements a REST API that sets Last-Modified header correctly. However, clients always receive 200 OK responses even when sending If-Modified-Since headers. What is the most likely cause?
Think about what the server must do to support conditional GET requests.
Even if the Last-Modified header is set, the server must explicitly check the If-Modified-Since header in the request and decide whether to return 304 Not Modified or the full content. If this logic is missing, the server always returns 200 OK.
Given a REST API endpoint, which pseudocode snippet correctly implements conditional GET using Last-Modified and If-Modified-Since headers?
Remember the server returns 304 only if the resource was not modified after the date the client provides.
The server compares the If-Modified-Since date with the resource's Last-Modified date. If the resource was not modified after the date, it returns 304 Not Modified. Otherwise, it returns the full resource with Last-Modified header.