Put和幂等 [英] Put and idempotent

查看:188
本文介绍了Put和幂等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您模型包含提起被称为创造和更新

当您使用PUT来更新内容,这一纪录。


  1. 应该创建设置为数据创建或修改的时间呢?由于PUT是幂等的,所以它不应该依赖于previous值


  2. 由于更新在发出请求总是修改,所以它违反幂等的原则?



解决方案

  

如若创建被设置为数据创建或修改的时间?由于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..

  1. Should created be set to the time of data creation or modification? Since PUT is idempotent, so it should not rely on previous value

  2. 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 identical PUT multiple times, idempotence is not violated since these subsequent requests don't modify any of the attributes, and thus the updated_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 send created_at or updated_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 a PUT should send the entire object. However, if that idea is ignored (as it often is in Rails, and perhaps elsewhere), then PUT is indeed idempotent.

这篇关于Put和幂等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆