Put和幂等 [英] Put and idempotent
问题描述
如果您模型包含提起被称为创造和更新
当您使用PUT来更新内容,这一纪录。
-
应该创建设置为数据创建或修改的时间呢?由于PUT是幂等的,所以它不应该依赖于previous值
-
由于更新在发出请求总是修改,所以它违反幂等的原则?
如若创建被设置为数据创建或修改的时间?由于PUT是幂等的,所以它不应该依赖于previous值。
块引用>我真的不明白你问这里。没有理由
created_at
将被设置为修改时间,因为它们是两个截然不同的概念。
由于更新在发出请求总是修改,所以它违反幂等的原则?
块引用>您假设
的updated_at
始终修改是不正确的(至少在Rails的,也不应该是其他地方)。如果你这样做相同的PUT
多次幂等不受侵犯,因为这些后续请求不修改任何属性,因而的updated_at
时间的不的改变。有一个有趣的<一个href=\"http://weblog.rubyonrails.org/2012/2/25/edge-rails-patch-is-the-new-primary-http-method-for-updates/\"相对=nofollow>后在铁轨上博客关于
PUT
&安培;PATCH
是增添了更多的这一点。我看到它的方式,用户不应该送created_at
或的updated_at
与他们的请求(由于服务器或许应该平时忽略它们,并将它们设置本身),但它确实是有问题的,如果这违反了想法,一个PUT
应该发送整个对象。但是,如果这个想法被忽略(因为它往往是在Rails中,也许其他地方),那么PUT
确实幂等。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?
解决方案Should created be set to the time of data creation or modification? Since PUT is idempotent, so it should not rely on previous value.
I don't really understand what you're asking here. There's no reason
created_at
would be set to the modification time, since they are two distinct concepts.Since updated is always modified when you issue the request, so it violated the principle of idempotent?
Your assumption that
updated_at
is always modified isn't true (at least not in Rails, nor should it be anywhere else). If you do an identicalPUT
multiple times, idempotence is not violated since these subsequent requests don't modify any of the attributes, and thus theupdated_at
time is not changed.There is an interesting post on the Rails blog about
PUT
&PATCH
that adds a lot more to this. The way I see it, the user should never sendcreated_at
orupdated_at
with 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 aPUT
should send the entire object. However, if that idea is ignored (as it often is in Rails, and perhaps elsewhere), thenPUT
is indeed idempotent.这篇关于Put和幂等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!