I am designing a system where the user interface will be constructed using a mixture of task oriented UI and CRUD UI. This way we want to be able to have an optimal user experience for different user roles.
The client application uses REST/JSON to communicate with the application server.
For the CRUD part the REST API part is mostly straight foreward. But designing the API for the task oriented actions in our application is a little bit more difficult.
How would one go about designing a REST API that makes a distinction between two different actions on a resource that both actually just update the data?
As an example - The user can change a person's address for the following reasons:
Both reasons result in the same end situation; the data has changed. But in the REST API there should somehow be a difference to be able to react differently.
Generally a REST resource will be a noun. However, it is also legitimate for the resource to be a process or process step. Thus for the example you've given, I might do this:
PUT /resource/customer/123/address
POST /resource/customer/123/changeOfAddress
In the latter case, the HTTP body would presumably contain additional information such as "effective date". Also, the content-location header returned from the above POST likely would contain the URI to resource that shows the old address, the new address, and when the transition occurred.
Thus the changeOfAddress is nominally a "process" but it is practically a noun unto itself; from a modelling POV, it is a first-class citizen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With