Let's have a data structured like this:
users: [{
"name": "username1",
"garages": [{
"name": "my one garage even though I may have several",
"adress": "some adress"
"cars": [{
"name": "subaru"
"color": "red"
},{
"name": "toyota"
"color": "black"
}]
}]
},{
// other users ...
}]
and I want to change it to something like this:
users: [{
"name": "username1",
"garages": [{
"name": "my one garage even though I may have several",
"adress": "some different address"
"cars": [{
"name": "toyota"
"color": "black"
},{
"name": "mercedes"
"color": "white"
},{
"name": "nisan"
"color": "red"
}]
}]
},{
// other users ...
}]
Now to make changes like this, the user has access to a page of "garage edits" which has a form that contains the details of his garages (name and adress) as well as the cars in each garage and their details.
Then a submit button with make patch call to the api with the new data.
It's the only way the user can add or remove cars by the way.
No car can exist outside a garage and each car's identifier is also based on the garage it's in.
Meaning a black toyota in garage 1 is different than a black toyota garage 2.
Also a garage can't have 2 same cars.
Some of these rules may seem weird in this exemple but they do make sens in my actual context.
Now this PATCH will UPDATE some data from my t_garages table but also INSERT and DELETE into and from my t_cars table. So i'm just not sure about which http status code the api should send back if the transaction was succesful.
Use 200 OK
with a response body containing the updated garage data (including cars). This makes it clear to the client what the final state is after your transactional changes (update garage, insert cars, delete cars).Alternatively, if you want to save bandwidth and the client doesn't need the updated resource back, 204 No Content
is acceptable.