Bird
Raised Fist0
Rest APIprogramming~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What does the If-None-Match header do in a REST API request?
easy
A. It asks the server to send data only if it has changed since the last request.
B. It forces the server to ignore caching and send fresh data every time.
C. It tells the server to delete the cached data on the client side.
D. It requests the server to send the full data regardless of changes.

Solution

  1. Step 1: Understand the purpose of If-None-Match

    This header sends the ETag value from the client to check if the resource has changed.
  2. Step 2: Determine the server's response based on the ETag

    If the ETag matches, the server returns 304 Not Modified, meaning no new data is sent.
  3. Final Answer:

    It asks the server to send data only if it has changed since the last request. -> Option A
  4. Quick Check:

    If-None-Match checks changes [OK]
Hint: If-None-Match checks if data changed before sending [OK]
Common Mistakes:
  • Thinking it forces fresh data every time
  • Confusing it with cache deletion
  • Assuming it always sends full data
2. Which of the following is the correct syntax for sending an If-None-Match header with ETag value "abc123" in an HTTP request?
easy
A. If-None-Match: abc123
B. If-None-Match = "abc123"
C. If-None-Match: "abc123"
D. If-None-Match => abc123

Solution

  1. Step 1: Recall HTTP header syntax

    Headers use colon : to separate name and value, and ETag values are quoted strings.
  2. Step 2: Identify correct quoting and separator

    If-None-Match: "abc123" uses colon and quotes correctly: If-None-Match: "abc123".
  3. Final Answer:

    If-None-Match: "abc123" -> Option C
  4. Quick Check:

    Headers use colon + quoted ETag [OK]
Hint: Headers use colon and quotes for ETag values [OK]
Common Mistakes:
  • Omitting quotes around ETag
  • Using equals or arrow instead of colon
  • Not quoting the ETag string
3. Given this server logic:
if request.headers.get('If-None-Match') == current_etag:
    return 304
else:
    return 200 with data and ETag

What will the server respond if the client sends If-None-Match: "xyz789" but current_etag is "abc123"?
medium
A. 200 OK with data and ETag
B. 304 Not Modified
C. 400 Bad Request
D. 500 Internal Server Error

Solution

  1. Step 1: Compare client's ETag with server's current ETag

    The client sends "xyz789" but the server's current ETag is "abc123", so they do not match.
  2. Step 2: Determine server response based on mismatch

    Since ETags differ, the server sends full data with status 200 and the current ETag.
  3. Final Answer:

    200 OK with data and ETag -> Option A
  4. Quick Check:

    ETags differ -> send data [OK]
Hint: If ETags differ, server sends full data (200) [OK]
Common Mistakes:
  • Assuming 304 when ETags differ
  • Confusing 400 or 500 errors with ETag mismatch
  • Ignoring quotes in ETag comparison
4. A developer wrote this code snippet to handle If-None-Match but it always returns 200 OK even when ETags match:
if request.headers['If-None-Match'] == current_etag:
    return 200, data
else:
    return 304

What is the main error?
medium
A. The server must always return 200 regardless of ETag.
B. The code should compare request.headers.get() instead of direct indexing.
C. The ETag values should be stripped of quotes before comparison.
D. The 200 and 304 status codes are swapped in the if-else blocks.

Solution

  1. Step 1: Analyze the if condition and returned status codes

    The code returns 200 OK when ETags match, but it should return 304 Not Modified instead.
  2. Step 2: Identify correct status code usage for ETag match

    When ETags match, server returns 304 to avoid sending data; else returns 200 with data.
  3. Final Answer:

    The 200 and 304 status codes are swapped in the if-else blocks. -> Option D
  4. Quick Check:

    ETag match -> 304, not 200 [OK]
Hint: 304 means no change; 200 means send data [OK]
Common Mistakes:
  • Returning 200 on ETag match
  • Confusing header access methods
  • Ignoring quotes in ETag comparison
5. You want to optimize your REST API to reduce bandwidth by using If-None-Match. Which of the following sequences correctly describes the client-server interaction to achieve this?
hard
A. Client sends request with If-None-Match -> Server always returns 200 with data and ETag -> Client caches data
B. Client sends request without ETag -> Server sends data with ETag -> Client caches data and ETag -> Client sends request with If-None-Match header -> Server returns 304 if data unchanged
C. Client sends request with ETag in body -> Server returns 304 if data unchanged -> Client discards cached data
D. Client sends request without headers -> Server returns 304 if data unchanged -> Client updates cache

Solution

  1. Step 1: Understand the correct use of If-None-Match and 304

    The client first gets data and ETag, caches them, then sends If-None-Match with ETag to check for changes.
  2. Step 2: Identify the correct sequence

    The sequence that starts with an initial request without the ETag header, receives data and ETag from the server, caches both, and then uses If-None-Match on future requests, receiving 304 if unchanged, is correct.
  3. Final Answer:

    Client sends request without ETag -> Server sends data with ETag -> Client caches data and ETag -> Client sends request with If-None-Match header -> Server returns 304 if data unchanged -> Option B
  4. Quick Check:

    Proper If-None-Match flow [OK]
Hint: Initial fetch no ETag, then use If-None-Match with ETag [OK]
Common Mistakes:
  • Sending ETag in request body instead of header
  • Expecting 304 without sending If-None-Match
  • Ignoring caching after 304 response
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard