Reputation: 353
Several authors say that in the REST architecture, the POST method should be used to create a new resource, and only the PUT method is used to update an existing resource (or create a new one). But the problem is that the PUT method is idempotent, so if a resource has a date field named "updatedTime" that must be set in the server side for reliability, the updated operation is no longer idempotent (because the value of the "updatedTime" will always change in each new operation), so PUT can not be used, and as POST is used only to create a new object how to fix this?
Upvotes: 3
Views: 2274
Reputation: 14080
AS per HTTP's definition of idempotent :
Like the definition of safe, the idempotent property only applies to
what has been requested by the user; a server is free to log each
request separately, retain a revision control history, or implement
other non-idempotent side effects for each idempotent request.
So you're free to modify the updated time in an underlying server object as long as it doesn't affect the resource served by the HTTP server.
If you're concerned about breaking idempotency (although one could debate whether it is a real violation), I would therefore advise you to store updatedTime
in a server object field but only expose information about it through an appropriate Last-Modified header instead of putting it in the response body that represents the resource.
As a side note, POST is not only to create resources (see the spec)
Upvotes: 2