且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

HTTP方法:DELETE与POST

更新时间:2022-03-14 05:45:03

这里的问题是:请求 idempotent ?如果您执行两次相同的请求,是否有副作用?就像你订购一篇文章一样,两次执行订单请求会得到两次文章。

The question here is: Is the request idempotent? If you execute the same request twice, does it have a side effect? Like when you order an article, executing the order request twice would get you the article twice.

在这种情况下, POST 是您想要的方法。如果没有,那么你想要 PUT DELETE

In that case, POST is the method you want. If not, then you want either PUT or DELETE.

因为你似乎没有删除会话,只改变它的状态, PUT 将是一个更好的方法,因为它意味着资源被改变了,而不是删除,在您的情况下就是这种情况。

As you don't seem to be deleting the session, only altering its state, PUT would be a better method, because it means that the resource is altered, and not deleted, which is the case in your case.

编辑:

如果资源似乎从客户端删除, DELETE 似乎更合适。如何在后面实现事情对客户来说无关紧要。

If the resource appears to be deleted from the client, DELETE seems more appropriate. How things are implemented in the back doesn't matter for the client.