0
0
Rest APIprogramming~20 mins

If-None-Match and 304 responses in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
HTTP Caching Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What does the If-None-Match header do in an HTTP request?
Choose the best description of the purpose of the If-None-Match header in an HTTP request.
AIt tells the server to send the resource only if the ETag does not match the given value.
BIt forces the server to ignore caching and always send the full resource.
CIt instructs the server to send a 500 Internal Server Error if the ETag matches.
DIt requests the server to delete the resource if the ETag matches the given value.
Attempts:
2 left
💡 Hint
Think about how caching works and when a server decides to send a full response or not.
Predict Output
intermediate
1:00remaining
What is the HTTP status code returned when If-None-Match matches the resource ETag?
Given a client sends a request with If-None-Match header matching the current ETag of the resource, what status code does the server respond with?
A200 OK
B412 Precondition Failed
C404 Not Found
D304 Not Modified
Attempts:
2 left
💡 Hint
This status code means the resource has not changed since last fetched.
🔧 Debug
advanced
2:00remaining
Why does this server code always return 200 OK even when ETags match?
Consider this pseudocode for handling If-None-Match:
if request.headers['If-None-Match'] == resource.etag:
    return 200, resource.data
else:
    return 304, None
Why is this incorrect?
ABecause it returns 200 OK when ETags match instead of 304 Not Modified.
BBecause it does not check if the resource exists before comparing ETags.
CBecause it compares the wrong headers; should use If-Match instead.
DBecause it returns 304 Not Modified with resource data, which is invalid.
Attempts:
2 left
💡 Hint
Think about what status code means the resource has not changed.
📝 Syntax
advanced
1:30remaining
Which HTTP response header is required with a 304 Not Modified response?
When a server responds with 304 Not Modified, which header must it include to comply with HTTP standards?
AContent-Length
BETag
CContent-Type
DAuthorization
Attempts:
2 left
💡 Hint
This header helps the client validate the cached resource.
🚀 Application
expert
1:30remaining
How many bytes are sent in the response body when a 304 Not Modified is returned?
A client sends a GET request with an If-None-Match header matching the resource's ETag. The server responds with 304 Not Modified. How many bytes are sent in the response body?
AOnly the ETag string bytes
BThe full size of the resource in bytes
CZero bytes (empty body)
DA small JSON message explaining the status
Attempts:
2 left
💡 Hint
304 means the client should use its cached copy without new data.