api - 为什么 Stripe 使用 Post 方法来更新资源

标签 api http stripe-payments standards httpverbs

According to the RFC Put is used to update an existing resource.
但是,Stripe API 使用 Post更新对象。为什么是这样?
例如,在 Stripe Node Library

  update: stripeMethod({
    method: 'POST',
    path: '{id}',
  }),
update method电话POST我知道没有Patch方法,因为每次调用都必须发送整个资源,为什么是 Put在那种情况下不使用 HTTP 动词?
(与来自 an SO question about the Facebook API 的示例不同,资源可以通过 URL 中传递的单个 ID 进行标识)例如 URL 只是 /v1/customers/:id
Stripe Customer Update API Docs

最佳答案

有趣的问题!来自 your link :

The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server. [emphasis mine]


这意味着您必须PUT整个资源(变化和非变化)。很少有 API 是这样设计的。
来自 spec for POST :

The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line. POST is designed to allow a uniform method to cover the following functions:

  • Annotation of existing resources;

许多/大多数 API 已采用 POST作为更新对象的方式。
这里有一些额外的想法:https://stackoverflow.com/a/25909372/379538

关于api - 为什么 Stripe 使用 Post 方法来更新资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64796417/

相关文章:

javascript - Facebook Graph API 好友的姓名和 ID

php - Instagram API 被黑以允许上传?

android httpurlconenction 请求方法 405 不允许

javascript - Stripe 通话已记录,但未产生任何测试费用

ruby - 为以后使用 activemerchant 保存付款

javascript - AngularJS Edmunds REST API 调用 - 加载下拉菜单不起作用

java - 如果文件夹属于特定根文件夹,如何使用 java 通过 Api to Rally 获取信息

javascript - 如何调试 ReactJs/Redux 中浏览器网络操作的意外时间间隙?

.net - 使用 .NET 通过 HTTP 发送 Base64 编码字符串时出现问题

javascript - strip 验证失败时提交按钮不会重新启用