RESTful reordering of nested objects

I have a RESTful API that supports two objects, since the object A

contains an ordered list of nested objects B

:

Create object A               - POST  /a
Create object B and add to A  - POST  /a/<id>/b
Update object B in A          - PATCH /a/<id>/b/<id>

      

What would be a RESTful way to update the order of objects B

in a specific one A

?


Option 1: PATCH /a/<id>

with json content that replaces A.Bs


A

has a list of inline B

s, namely A.Bs

so that you can replace that list entirely, also changing the order on the path. It depends on whether the client has to resend the entire list correctly.

Option 2: PATCH /a/<id>

with json content that replaces A.B_order


Add separate ids list B

and update it with client. This is similar to option 1, but does not rely on retransmission of all objects. This requires the server to manage the list by updating it when it is created B

, and the update check contains all the necessary identifiers B

to update the list.

Option 3: PATCH /a/<id>/b

with json content that replaces A.Bs


Same as option 1, but with a different url

What would be the most RESTful and understandable?
Any other options?

+3


source to share


1 answer


I would suggest using the proposed standard as defined in RFC 6902 . In particular, the "move" op seems to be what you are looking for.



+2


source







All Articles