Loading published curriculum…

12 · Spring Boot and the web request lifecycle / LESSON 55 OF 102

Resource design, HTTP methods, and status codes

An API contract includes method semantics, status, headers, and response shape.

Before this lesson: Servlets, DispatcherServlet, filters, and interceptors

Understand the topic

GET should retrieve without intentional state changes. POST commonly creates a resource; return 201 and a Location header. PUT represents replacement and should be idempotent under its contract. PATCH applies a defined partial change; avoid treating an arbitrary entity JSON payload as a safe patch.

Distinguish missing resources, validation failures, authorization failures, and conflicts. Decide whether DELETE of an already missing resource is 204 or 404 and document it. Idempotence concerns intended server effects, not necessarily identical response bodies.

EXAMPLE · HTTP

HTTP examples

POST /api/tasks HTTP/1.1
Content-Type: application/json

{"title":"Learn HTTP"}

HTTP/1.1 201 Created
Location: /api/tasks/42
Content-Type: application/json

{"id":42,"title":"Learn HTTP","done":false}

What to expect

This is a request/response contract illustration, not one message to paste as a raw request.

YOUR TURN

Put it into practice

  1. 01Write a contract table for create, read, replace, complete, and delete.
  2. 02Specify success and failure statuses before implementing controllers.
  3. 03Verify: Tests check status, Location, and body shape for both valid and invalid requests.

Pass a quiz or complete a lab to check today’s streak. Each lesson counts once per day, including when you review it later.

UNDER THE HOOD

Build the mental model

An API contract includes method semantics, status, headers, and response shape.

  1. 01GET should retrieve without intentional state changes. POST commonly creates a resource; return 201 and a Location header. PUT represents replacement and should be idempotent under its contract. PATCH applies a defined partial change; avoid treating an arbitrary entity JSON payload as a safe patch.
  2. 02Distinguish missing resources, validation failures, authorization failures, and conflicts. Decide whether DELETE of an already missing resource is 204 or 404 and document it. Idempotence concerns intended server effects, not necessarily identical response bodies.
  3. 03Trace the example: This is a request/response contract illustration, not one message to paste as a raw request.

A mistake worth avoiding

A GET endpoint marks tasks complete when a crawler visits it.

DEBUGGING ROOM

Something broke. Where do you look?

A GET endpoint marks tasks complete when a crawler visits it.

Before revealing the diagnosis, write down your first investigation step.

CHECK YOUR UNDERSTANDING

Does idempotence require every repeated response body to be identical?

Choose one answer

BUILD IT YOURSELF

Write a contract table for create, read, replace, complete, and delete.

  1. 1.Write a contract table for create, read, replace, complete, and delete.
  2. 2.Specify success and failure statuses before implementing controllers.
  3. 3.Reproduce this failure, then repair it: A GET endpoint marks tasks complete when a crawler visits it.

Acceptance checklist

Lab completion is your self-report. Knowledge checks do not certify project quality.

RETRIEVE IT FROM MEMORY

Does idempotence require every repeated response body to be identical?

Revisit this lesson in three days after a successful check or lab.

Ready for the next step?

Tests check status, Location, and body shape for both valid and invalid requests.

Reading is separate from passing a knowledge check or completing a lab.

Go deeper · official references