Now I need to have the function of moving some child resources from one parent to another, such as A book is moved from one author to another.
My variant is:
POST /api/books/x/moveto/y
But how to create such an architect in a RESTful way?
It seems that your “move” operation is to replace the author of this book.
And PUT
Method seems to be the way to go:
07002
The
PUT
method requests that the state of the target resource be
created or replaced with the state defined by the representation
enclosed in the request message payload. […]
So you can have the endpoint as shown below :
PUT /api/books/{bookId}/author
The request payload will contain the representation of the new author.
I have a REST service.
Now I need to have the ability to move some child resources from one parent to another, such as a book Move from one author to another.
My variant is:
POST /api/books/x/moveto/y
But how to create such an architect in a RESTful way?
From the perspective of REST, URLs should be used to locate resources instead of expressing operations. To express operations, existing HTTP verbs should be used.
< /p>
It seems that your “move” operation is to replace the author of this book.
And the PUT
method seems to be the way to go:
07002
The
PUT
method requests that the state of the target resource be
created or replaced with the state defined by the representation
enclosed in the request message payload. […]
So, you can have an endpoint like the following:
PUT /api/books/{bookId}/author
The request payload will contain a representation of the new author.