gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 17:23:36 26 4
gpt4 key购买 nike

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 thesupplied Request-URI. If the Request-URI refers to an alreadyexisting resource, the enclosed entity SHOULD be considered as amodified 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 theentity enclosed in the request as a new subordinate of the resourceidentified by the Request-URI in the Request-Line. POST is designedto 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com