Send GET, HEAD, POST, PUT, PATCH, DELETE to Dodi’s gudang, once or three times: see which are safe and which are idempotent, right in his book. An interactive…
The wrong method makes quiet bugs: GET for an action that changes data (prefetchers, crawlers and reloads set it off too), or POST where it often repeats, so a double click makes duplicate data. Knowing which are safe and which are idempotent means knowing which may be repeated.
Safe and idempotent are two different properties
GET for an action that changes data GET is promised safe: links, prefetchers, crawlers and reloads may send it any time, so the action fires by accident. An action that changes data: POST/PUT/PATCH/DELETE from a form or fetch.POST is safe to retry POST is not idempotent: a double click or a retry makes duplicate data. Disable the button once sent, send an Idempotency-Key, or PUT to an id the client picks.PUT and PATCH PUT replaces all of it: the fields not sent are gone. PATCH changes part of it. Send PATCH for a partial change, or PUT with the whole object.POST 3× Three sends, three new parcels: POST is not idempotent.DELETE 3×: 204, then 404 The replies differ, the book is the same: still idempotent.HEAD GET’s stamp and headers, content-length included, without a single byte of body.PUT with { untuk } alone The fields not sent are gone: PUT replaces all of it.