I am still trying to wrap my head around certain cases in REST where using resources defined by names instead of verbs is less intuitive than in simple CRUD cases.
I have an "Update" resource, for updates/addons of the backend, with a Json representation as follows:
{
"id": 1,
"name": "Update Example",
"description": "demo update , adds handling of basic arduio type devices",
"version": "0.0.4",
"link":
{
"rel": "self",
"uri": "http://demo.org/updates/1",
"type: application/json"
},
}
EDIT: To clarify things a bit following Darrel Miller's answer: an updates "Updates" collection resource is already in place and it works like this:
- The back-end populates that collection based on a list of updates fetched (via polling) from an external server (that does not use rest, the update descriptions there are minimal, and pure text)
- The user using the API cannot add updates, all he can do is get the updates list, and install/ uninstall them
Now the problem is this:
I need to find a proper, restfull way to install updates via the API, and I came up with a few ways to do this, but they all seem "not quite right" to me:
1- Add a link to the Update resource, add an Installation resource and make use of hateoas
Add this to the update:
"link":
{
"rel": "Installation",
"uri": "http://demo.org/updates/1/installation",
"type: "application/json"
}
Installation resource :
{
"installing": false,
"installProgress": 0,
"link":
{
"rel": "self",
"uri": "http://demo.org/updates/1/installation",
"type: "application/json"
}
}
To start the installation process the user would then POST to demo.org/updates/1/installation to update "installing": false
to "installing": true
This seems like it would work but is it good practice to add the "installing" as a simple boolean attribute?
2- POST to a uri like demo.org/installations , to add a new Installation resource
Thereby starting the install process, and also requiring the addition of a link to the update being downloaded inside the newly created Installation resource :
{
"installProgress": 0,
"link":
{
"rel": "update",
"uri": "http://demo.org/updates/1",
"type: application/json"
},
}
While this may centralize the Installation resource logically into an Installations collections, my original reflex would have been to DELETE an item in this collection to stop its installation .
In that case if the Installation resource instance is gone , would the use of the "installation" link on the update have to recreate a new installation resource every time it is "navigated" ?
More generally, would it not be better to have an "installed" attribute in the Update itself to make sense overall ?
Also what if the user wants to pause something like an installation ?
I have looked at a lot of similar questions in various articles and here on stackoverflow, but i still am not quite sure what the best way to tackle these kinds of problems is. Also , I know REST is not about verbs (beyond the HTTP ones) but I still believe this is a valid question.
So please, any feedback is very welcome !
Thanks in advance.