Bird
0
0

A developer wrote this code snippet for handling validation-based caching:

medium📝 Debug Q6 of 15
Rest API - Caching Strategies
A developer wrote this code snippet for handling validation-based caching:
if request.headers['If-None-Match'] == resource.etag:
    return Response(status=200)
else:
    return Response(data=resource.data, status=200)

What is the error in this code?
AIt should compare If-Match header instead
BIt should always return status 404
CIt should return status 304 when ETags match
DIt should ignore ETag and always send data
Step-by-Step Solution
Solution:
  1. Step 1: Check correct status code for matching ETags

    When ETags match, server must return 304 Not Modified, not 200.
  2. Step 2: Identify fix in code

    Change status to 304 to indicate no data sent.
  3. Final Answer:

    It should return status 304 when ETags match -> Option C
  4. Quick Check:

    Matching ETags require 304 status = B [OK]
Quick Trick: Use 304 status for unchanged resource [OK]
Common Mistakes:
MISTAKES
  • Returning 200 instead of 304 on match
  • Confusing If-None-Match with If-Match
  • Ignoring caching headers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes