Question

In this presentation on REST (timestamp 17:00-18:45), the speaker says that an HTTP PUT must include all the properties for a resource, and not be used for partial updates. This is required in HTTP because otherwise it is not idempotent.

His definition of idempotency is (and this sounds reasonable):

idempotent is any operation that can be performed once or multiple times and result in the same server state

However, he then goes on to give an example where (paraphrased):

Request A: I use a PUT to update only the name property of a resource.

Request B: I use a PUT to update only the description.

In between A and B another client could specify the name, then after request B, the resource has the other client's name, and my description. Because the server state isn't the same after request A and B, that's not an idempotent operation.

I'm not sure about this interpretation: for me, idempotency only tells you something about what happens when you run the same operation multiple times in a row. In the above example, request A and B are two different operations, so there is no reason to think that running A then B should be have any special guarantees; in particular, there is no reason to think they should together constitute an atomic operation.

Running request A multiple times would have the same effect as running it once (likewise for B), so I would have thought it idempotent (even if this was an incorrect use of PUT for other reasons).

Is my understanding incorrect?

(Note: this is intended to be a question about the meaning of idempotency, not the appropriate use of PUT).

Was it helpful?

Solution

You are right; a partial update can be idempotent.

That doesn't change the fact that PUT is not for partial updates; if you need a partial update you ought to use PATCH.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top