REST service has two nodes
GET /items returns list of Items:
[
{
"id": 34,
"name": "apple",
"available_amount" : 10
},
{
"id": 37,
"name": "banana",
"available_amount" : 30
},
...
]
POST /orders creates order with requested items (assume we order 6 apples here) and returns the order:
{
"id": 12337,
"items": [
{
"id": 34,
"name": "apple",
"ordered_amount": 6
}
]
}
How do I inform the client application about the created order which also reduced the available_amount to 4 since 6 apples have been sold.
Do I return the affected resources with the order result, so the client knows what to update?
Like with nodes path:
{
"id": 12337,
"items": [
{
"item_id": 34,
"ordered_amount": 6
}
],
"affected_resources" : [
"/items/34"
]
}
or even the fully changed resource:
{
"id": 12337,
"items": [
{
"item_id": 34,
"ordered_amount": 6
}
],
"affected_resources": {
"items": [
{
"id": 34,
"name": "apple",
"available_amount": 4
}
]
}
}
or something completely different?
What is considered best practice in these cases?