If you model contains a filed which are called “created” and “updated”
When you use PUT to update content to this record..
-
Should created be set to the time of data creation or modification? Since PUT is idempotent, so it should not rely on previous value
-
Since updated is always modified when you issue the request, so it violated the principle of idempotent?
I don’t really understand what you’re asking here. There’s no reason
created_atwould be set to the modification time, since they are two distinct concepts.Your assumption that
updated_atis always modified isn’t true (at least not in Rails, nor should it be anywhere else). If you do an identicalPUTmultiple times, idempotence is not violated since these subsequent requests don’t modify any of the attributes, and thus theupdated_attime is not changed.There is an interesting post on the Rails blog about
PUT&PATCHthat adds a lot more to this. The way I see it, the user should never sendcreated_atorupdated_atwith their request (since the server should probably usually ignore them and set them itself), though it is indeed questionable if this violates the idea that aPUTshould send the entire object. However, if that idea is ignored (as it often is in Rails, and perhaps elsewhere), thenPUTis indeed idempotent.