[Discussion] Updates in the Greenfield API
See original GitHub issueWe need to take a decision over how to do updates in BTCPayServer, and then keep consistency.
Should a POST
update the whole structure or only specified field.
Imagine I want to update store with id 123
to my awesome store
.
Should make POST handle partial update like: POST/PUT or PATCH /store/123
{
"name": "my awesome store"
}
Or should POST update the whole thing, where you need to first GET /store/123
{
"name" : "old name",
"payjoinEnabled": true,
"defaultCurrency": "USD"
}
Then update the whole thing POST /store/123
{
"name" : "Awesome store",
"payjoinEnabled": true,
"defaultCurrency": "USD"
}
If some fields are not initialized, the server assume that it is set to a default value and update the field.
I am rejecting the following alternative:
- Make both POST and PUT. This would double the amount of work for us, while not providing something that still can’t be done already whichever what solution we chose.
- Using JSON PATCH. This is completely untyped, difficult to use, and not really spread anyway.
I checked how for example did slack API, and they seem to support POST with partial updates.
Twitter is also doing POST with partial update, but instead pass all by query string.
I think that from API perspective it makes sense to support partial update for POST.
Two API that need to be fixed if we decided to go that route:
- Update payment requests
- Update store
Issue Analytics
- State:
- Created 3 years ago
- Comments:18 (13 by maintainers)
Top GitHub Comments
If you’re triggering some action based on a specific property change, you still need to validate that the value changed in comparison to the old value, so there is nothing gained in that regard.
I think it’s much more likely that you would have the whole object on the client, and if not, you can easily retrieve it before you update.
On Sat, 30 May 2020, 15:03 kmenashe, notifications@github.com wrote:
Just takking from my experience I had recently…say you have a property update that triggers some post update actions. If you have full input object, you need to figure out what property was change and act upon. Partial specifies the relevant properties so no need to identify them. In addition, some times you don’t have the entire object on the client, and partial will still allow you to update. Hope I am making sense here.