We have an inventory feature where we generate Bills. There is a Edit Bill API call. We are confused to implement this as PATCH Or PUT.
let's say our BillLineItem consists of
{
stockId
quantity
rate
}
A Bill with id = 1 has 2 LineItems :
| Stock Id | Qty | Rate |
| 10 | 2 | 10 |
| 11 | 3 | 20 |
Now lets say I want to change the quantity for stock Id : 10 to 5
and
I want to change the rate for stock Id : 11 to 40
Should I represent this as PUT Call like :
bill : {
id : 1
lineItems : [
{
stockId : 10,
qty : 5,
rate : 10
},
{
stockId : 11,
qty : 3,
rate : 40
}
]
}
Should I represent this as PATCH Call like :
bill : {
id : 1
lineItems : [
{
stockId : 10,
qty : 5,
},
{
stockId : 11,
rate : 40
}
]
}
There are other parameters like discountType, discountValue as part of BillLineItem which I have not shown in the above example.
Wikipedia describes the typical way that HTTP methods correspond to RESTful operations:
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.
Since you're updating individual properties of bill items rather than replacing them completely, PATCH
is the appropriate method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With