使用POST在Rest中删除/更新? [英] Use POST for delete/update in Rest?

查看:357
本文介绍了使用POST在Rest中删除/更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我理解(来自已接受的答案 HTTP和之间的区别是什么? REST?
REST只是一套关于如何使用HTTP的规则

I understand (From accepted answer What is the difference between HTTP and REST?) that REST is just a set of rules about how to use HTTP

接受的答案说


不,REST是应该使用HTTP的方式。

No, REST is the way HTTP should be used.

今天我们只使用一小部分HTTP协议的方法 - 即
GET和POST。 REST的方法是使用所有协议的
方法。

Today we only use a tiny bit of the HTTP protocol's methods – namely GET and POST. The REST way to do it is to use all of the protocol's methods.

例如,REST规定使用DELETE来删除文档(是
它是URI后面的文件,状态等),而使用HTTP,你会
滥用GET或POST查询,如... product /?delete_id = 22

For example, REST dictates the usage of DELETE to erase a document (be it a file, state, etc.) behind a URI, whereas, with HTTP, you would misuse a GET or POST query like ...product/?delete_id=22

我的问题是什么缺点/缺点(技术或设计)如果我继续使用POST方法而不是DELETE / PUT删除/更新Rest中的资源?

My question is what is the disadvantage/drawback(technical or design) If I continue to use POST method instead of DELETE/PUT for deleting/updating the resource in Rest ?

推荐答案


我的问题是什么是缺点/缺点(技术或设计)
如果我继续使用POST方法而不是DELETE / PUT for
删除/更新Rest中的资源?

My question is what is the disadvantage/drawback(technical or design) If I continue to use POST method instead of DELETE/PUT for deleting/updating the resource in Rest ?

POST 请求不是 Idempotent 但是 DELETE 请求 Idempotent

The POST request is not Idempotent but the DELETE request is Idempotent.

幂等HTTP方法是一种可以多次调用而没有不同结果的HTTP方法

Idempotency 在构建容错 API时非常重要。

Idempotency is important in building a fault-tolerant API.

假设客户想通过 POST 更新资源。由于POST不是幂等方法,因此多次调用可能会导致错误更新。如果您向服务器发送POST请求会发生什么,但是会超时。资源实际更新了吗?在将请求发送到服务器或客户端响应期间是否发生了超时?我们可以再次安全地重试,或者我们是否需要首先弄清楚资源发生了什么?通过使用幂等方法,我们不必回答这个问题,但我们可以安全地重新发送请求,直到我们真正从服务器获得响应。

Suppose a client wants to update a resource through POST. Since POST is not an idempotent method, calling it multiple times can result in wrong updates. What would happen if you sent out the POST request to the server, but you get a timeout. Is the resource actually updated? Does the timeout happened during sending the request to the server, or the response to the client? Can we safely retry again, or do we need to figure out first what has happened with the resource? By using idempotent methods, we do not have to answer this question, but we can safely resend the request until we actually get a response back from the server.

所以,如果你使用POST进行删除,会有后果。

So, if you use POST for deleting, there will consequences.

这篇关于使用POST在Rest中删除/更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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