I am starting to learn REST (for my own project), and at the same time experimenting with Philips Hue API. I have discovered a strange IMO effect: to switch a light on, I need to PUT
{"on": true}
to /api/<KEY>/lights/6/state
. The light status can be retrieved with GET
on /api/<KEY>/lights/6/
, and I receive e.g.
{
"state": {
"on": true,
"bri": 113,
"alert": "none",
"reachable": true
},
"type": "Dimmable light",
"name": "Light 6",
"modelid": "LWB006",
"manufacturername": "Philips",
"uniqueid": "00:17:89:01:11:57:da:8d-0b",
"swversion": "5.38.1.15095"
}
However I cannot GET
anything from /api/<KEY>/lights/6/state
:
[
{
"error": {
"type": 3,
"address": "/lights/6/state",
"description": "resource, /lights/6/state, not available"
}
}
]
I am not sure I actually read it anywhere, but the feeling I've got from reading many different texts about REST tells me that if I can PUT
/api/endpoint
, I should also be able to GET
it back. So if I designed the API, it would be either PUT
{"state": {"on": true}}
at /lights/6
or GET
/lights/6/state
would have returned {"on": true}
.
Is there any general agreement on this?
UPDATE: As was righteously mentioned, I haven't actually referenced anything. Trying to find references now, I managed to find a popular tutorial, which seems to start plain wrong to me:
PUT - Used to create a new resource.
POST - Used to update a existing resource or create a new resource.
I believe all other resources, e.g. this and this, are clear in that POST should not be used to update.
But in general, REST is based on URLs that identify "resources". So if I can PUT data to a resource, I should also be able to GET data from that resource. I couldn't find it written explicitly anywhere, but doesn't the notion of resources imply it?