gpt4 book ai didi

rest - PATCH 与 PUT 更新法案

转载 作者:行者123 更新时间:2023-12-04 23:35:39 25 4
gpt4 key购买 nike

我们有一个库存功能,我们可以在其中生成账单。有一个 Edit Bill API 调用。我们很困惑将其实现为 PATCH 或 PUT。

假设我们的 BillLineItem 包括

{
stockId
quantity
rate
}

id = 1 的账单有 2 个 LineItems :
|  Stock Id |   Qty        |  Rate       |
| 10 | 2 | 10 |
| 11 | 3 | 20 |

现在假设我想更改 quantity for stock Id : 10 to 5
我要换 rate for stock Id : 11 to 40
我应该将其表示为 像这样调用:
bill : {
id : 1

lineItems : [
{
stockId : 10,
qty : 5,
rate : 10
},

{
stockId : 11,
qty : 3,
rate : 40
}
]
}

我应该将其表示为 补丁 像这样调用:
 bill : {
id : 1

lineItems : [
{
stockId : 10,
qty : 5,
},

{
stockId : 11,
rate : 40
}
]
}

还有其他参数,如discountType、discountValue 作为BillLineItem 的一部分,我没有在上面的示例中显示。

最佳答案

Wikipedia描述了 HTTP 方法对应于 RESTful 操作的典型方式:

PUT - Replace all the representations of the member resources of the collection resource with the representation in the request body, or create the collection resource if it does not exist.
PATCH - Update all the representations of the member resources of the collection resource using the instructions in the request body, or may create the collection resource if it does not exist.



由于您正在更新账单项目的各个属性而不是完全替换它们, PATCH是合适的方法。

关于rest - PATCH 与 PUT 更新法案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57816417/

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