HTTP idempotence (source code)

= HTTP idempotence
{c}

<HTTP idempotence> means that multiple identical requests have the same intended server-side effect as one request. It concerns the requested resource operation, rather than requiring every part of server state or every returned message to remain identical. The <HTTP request methods> defined as idempotent include `PUT`, `DELETE` and the <HTTP safe methods>.<HTTP Semantics>[§9.2.2, idempotent methods and intended effects]{ref}

A small state model makes the distinction precise. Let $e\in\{0,1\}$ indicate whether a resource exists, and model deletion by $f(e)=0$. Then
$$
f(f(e))=0=f(e).
$$
Deleting again cannot make the resource more absent. Contrast an application operation that appends an item to a list: applying it twice can add two items.

For an invented endpoint, suppose a first `DELETE` removes an item and returns `204`, while a second returns `404` because it is already absent. The intended final existence state agrees after one or two requests, although the <HTTP status codes> differ. These particular responses are stipulated for the example, not required for every deletion endpoint.

Idempotence also differs from read-only behavior. The first deletion can change a resource, whereas an <HTTP safe method> requests essentially read-only semantics. Separate logging or revision history can change on repeated requests without contradicting idempotence of the intended operation.<HTTP Semantics>[§§9.2.1–9.2.2, safe semantics and separate side effects]{ref}

This property matters when a connection fails before a client receives the response: repeating an idempotent request can recover the intended result without needing to know whether the earlier attempt completed. It does not establish that the operation was executed only once. A method without a general idempotence guarantee can still implement a particular application operation that is idempotent, but that requires additional knowledge of its semantics.<HTTP Semantics>[§9.2.2, communication failure and retry discussion]{ref}