1. What is the precise architectural difference between POST, PUT, and PATCH, and which methods are idempotent?
POST is used to create a new subordinate resource; it is neither safe nor idempotent (calling POST twice creates two separate records). PUT is used to replace an entire resource at a known URI; it is idempotent (executing the identical PUT request multiple times produces the identical server state). If the resource does not exist, PUT can create it or return 404 depending on API contract. PATCH performs partial updates, modifying only specified attributes without requiring the complete payload representation; PATCH is generally non-idempotent by default unless controlled with version tokens.
// 1. POST: Creates a new user record (non-idempotent)
// POST /api/v1/users -> Status 201 Created
// 2. PUT: Completely replaces the user representation (idempotent)
// PUT /api/v1/users/42 -> Status 200 OK
// Payload: { "name": "Jane", "email": "jane@example.com", "role": "admin" }
// 3. PATCH: Partially updates only specific fields
// PATCH /api/v1/users/42 -> Status 200 OK
// Payload: { "role": "super-admin" }