Skip to content
Ameen Abozaid
JNR-017

HTTP in depth

  • 6 Lessons
  • 2 h practice (estimate)
On this page 8 topics

Overview

Topics

  • Methods
  • idempotency
  • safe methods
  • headers
  • content negotiation
  • caching

Learn first

2 h of practice (estimate)

Learning outcomes

  1. Classify methods as safe and/or idempotent and explain why it matters for retries.
  2. Use request and response headers for content negotiation (Accept, Content-Type).
  3. Explain HTTP caching (Cache-Control, ETag, conditional requests) and when to disable it.
  4. Explain HTTP versions and connection reuse at a conceptual level.

Lessons

  1. 01Methods revisited: safety and idempotency
  2. 02Headers that matter to backend engineers
  3. 03Content negotiation
  4. 04Caching and conditional requests
  5. 05HTTP/1.1, HTTP/2, HTTP/3 in brief
  6. 06Demo: conditional GET with ETags and curl

Lab and exercises

Lab

JNR-017-LAB1 · ETags

Outcomes: 1–4 · Time: ~2 h Add ETag support to GET /products/{id} in the Shop API. Derive the ETag from the product's content or version. Honor If-None-Match by returning 304 Not Modified with no body. Show the full exchange with curl -i.

Acceptance: the second request (with If-None-Match) returns 304 with no body; after an update the ETag changes and the response is 200.

Exercises (assessment: quiz plus lab)

IDOutcomeTask
JNR-017-EX011Classify GET, HEAD, POST, PUT, PATCH, DELETE as safe and/or idempotent in a table.
JNR-017-EX021A client retries POST /orders after a timeout. Describe what can go wrong and one way to prevent it.
JNR-017-EX032Make GET /products/{id} return JSON only and show the status for Accept: application/xml.
JNR-017-EX043Choose a Cache-Control value for: a public product image, a user's order list, a bank balance. Justify each.
JNR-017-EX053Using curl -i, record a 200 with ETag and then a 304 for the same URL.
JNR-017-EX064Write three sentences: what connection reuse is and what HTTP/2 adds over HTTP/1.1.
Show solutions
  • EX01 Safe: GET, HEAD. Idempotent: GET, HEAD, PUT, DELETE. PATCH and POST are neither guaranteed.
  • EX02 The server may create two orders. Prevent with an idempotency key header that the server remembers (covered later in MID-029).
  • EX03 @GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE); XML request gives 406.
  • EX04 Image: public, max-age=86400. Order list: private, no-cache (or short private max-age). Balance: no-store.
  • EX05 curl -i URL then curl -i -H 'If-None-Match: "<etag>"' URL; second response has 304 and no body.
  • EX06 Connection reuse avoids repeated TCP/TLS setup; HTTP/2 multiplexes many requests on one connection and compresses headers.

Outcome 2 (headers) is also checked by quiz Q04 and Q05; outcome 4 by quiz Q09 and Q10.

Quiz

Outcomes: O1 safe and idempotent · O2 content negotiation · O3 caching · O4 HTTP versions.

A self-check for you: nothing is graded, saved or sent anywhere. Choose an answer, then check it. You can try again as often as you like.

  1. 1Which method is safe?O1
  2. 2Which method is idempotent but not safe?O1
  3. 3Why does idempotency matter?O1
  4. 4The Accept header says:O2
  5. 5A client posts a body type the server cannot read. Expected status:O2
  6. 6A 304 response means:O3
  7. 7Which header sends the client's stored ETag back?O3
  8. 8Which is right for a response with a user's private data?O3
  9. 9HTTP/2 multiplexing means:O4
  10. 10Why reuse connections?O4

Practical part

Six exercises JNR-017-EX01 to EX06 plus the ETag lab. Pass: at least five exercises and a lab where the second request returns 304 with no body.

Common mistakes

POST for everything; non-idempotent PUT; caching personalized responses.

Assessment

Quiz plus lab.

Career relevance

Retries and idempotency (MID-029, MID-033).

Type to search levels, phases, modules and lessons.