0
0
Rest APIprogramming~20 mins

Response headers (Cache-Control, ETag) in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cache-Control & ETag Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this HTTP response header?

Consider a REST API response with the following headers:

Cache-Control: max-age=3600, must-revalidate
ETag: "abc123"

If a client sends a request with header If-None-Match: "abc123", what will the server most likely respond with?

AHTTP 304 Not Modified with no body
BHTTP 200 OK with full response body
CHTTP 500 Internal Server Error
DHTTP 403 Forbidden
Attempts:
2 left
💡 Hint

ETag helps the server decide if the resource has changed.

🧠 Conceptual
intermediate
1:30remaining
Which Cache-Control directive forces revalidation every time?

Which Cache-Control directive ensures that the client must check with the server before using a cached response?

Apublic
Bmax-age=3600
Cno-cache
Dprivate
Attempts:
2 left
💡 Hint

Think about which directive means 'always check before use'.

Predict Output
advanced
2:00remaining
What is the effect of this Cache-Control header?

Given this response header:

Cache-Control: private, max-age=0, must-revalidate

What does this mean for caching behavior?

AThe response is not cached anywhere
BThe response is cached by any cache and never revalidated
CThe response is publicly cached and served without revalidation for 1 hour
DThe response is cached only by the browser and must be revalidated before each use
Attempts:
2 left
💡 Hint

Consider what private and max-age=0 imply together.

Predict Output
advanced
1:30remaining
What error occurs with this ETag usage?

Consider this server code snippet that sets ETag header incorrectly:

response.headers['ETag'] = 12345

What error or behavior will this cause?

ATypeError because header value must be a string
BSyntaxError due to invalid header format
CThe ETag header is ignored silently
DThe server sends ETag as a string "12345" without error
Attempts:
2 left
💡 Hint

HTTP headers must be strings.

🧠 Conceptual
expert
2:30remaining
How does ETag improve REST API efficiency?

Which statement best explains how ETag headers improve REST API efficiency?

AETag forces servers to always send full responses to clients
BETag enables clients to send conditional requests to avoid downloading unchanged resources
CETag allows clients to cache responses indefinitely without revalidation
DETag disables caching and forces fresh data every time
Attempts:
2 left
💡 Hint

Think about how clients can save bandwidth using ETag.