Imagine the following situation. 2 types of resources. The first type is ‘requested_x’ the second type is ‘accepted_x’.
To create an instance of ‘accepted_x’ there must be an instance of ‘requested_x’ before which ‘updates / changes’ to an ‘accepted_x’ .
How to model this?
Idea A - "Use one type with a status attribute."
That would be a possible solution, but for some “external” reasons, I don’t want to use it in this case.
Idea B - “Let the client deal with it”:
Use a CREATE request to create ‘accepted_x’ and then a DELETE request to delete ‘reqested_x’.
Disadvantage: There is no ‘transaction / transactional-behaviour’ meaning the the client can ‘forget’ to call the DELETE etc.
Idea C - “Use PATCH”:
Use a PATCH request to update the ‘requested_x’ to a ‘accepted_x’.
Where in my case the type and maybe also the id of the resource will change.
Advantages:
- The requirement that the resource of type ‘requested_x’ exists is easy to prove.
- The UPDATE / DELETE of the old resource happens on the server (transactional-behavior).
Is this allowed by JSON API?
How would the response look like?
How would the client be informed about the deletion?
Idea D - “CREATE with DELETE”:
Use a CREATE request to create the ‘accepted_x’ instance. The reference to the ‘requested_x’ instance comes within the CREATE requested and is used to a) check the existence and b) delete it after the creation.
How would the response look like?
How would the client be informed about the deletion?
Are ‘Version’ attributes and meta data informations (‘links’…) the way to go?