Web Technology Basics
Among HTTP methods, which of the following is not "safe" (not intended to change the state of resources on the server) but is "idempotent" (sending the same request any number of times leaves the same state as sending it once)?
- AGET
- BPOST
- CPUT
Show answer and explanation
Answer: C. PUT
GET and HEAD are safe methods that only read resources, and safe methods are also idempotent. PUT replaces the state of the specified resource with the content sent, so sending it any number of times gives the same result as sending it once: it is idempotent but not safe. DELETE is likewise idempotent. POST may create a new order or post each time it is sent, so it is generally not idempotent, and PATCH is not necessarily idempotent either. An idempotent request has the advantage that it can simply be resent when a communication failure leaves the result unknown, with little risk of problems.
- A. GET only reads resources, so it is both safe and idempotent.
- B. POST may create a new resource each time it is sent, so it is generally neither safe nor idempotent.
- C. Correct. PUT replaces the resource with the content sent, so any number of sends leaves the same state.