views:

122

answers:

3

I understand how to use REST for doing general entity interactions - using urls names to map to entities and the HTTP verbs to map to actions on those entities. But what is the generally accepted way of looking at "actions" more like RPC?

For example, let's say I want to send a command for the device to reset? There's no real "entity" here or do I do something like POST to http://mydevice/device/reset?

+1  A: 

I usually name the entity "system" or something like that. So you do "/system/reset". You've chosen device so that works too.

But yea, I usually consider these types of actions to be updates, which would use the POST method. So I think you are right to POST to /device/reset

ocdcoder
Funny you should key in on the PUT/POST thing - I just asked about that as well: http://stackoverflow.com/questions/2447677/rest-verbs-which-convention-is-correct/2447714#2447714
ctacke
I'll comment on that, but I also use a REST-variation as not all clients handle PUT/DELETE. Read the wikipedia page for REST: http://en.wikipedia.org/wiki/Representational_State_Transfer
ocdcoder
Yes, I read the Wikipedia article. Since I'm controlling both the service and the client end, I've got the luxury of using all 4 verbs.
ctacke
+4  A: 

/device/reset or /system/reset are ok.

The REST "design pattern" does encourage you to NOT use any verbs.. You could do:

POST http://mydevice/system/state    
<stateType>RESET</stateType>

Related information:

Marcus
Yes, that is a possible solution.
Jan Algermissen
+3  A: 

I don't think that's the case to use POST. The "RESET action" is a idempotent action (if you call it n times you will always get the same result), so IMHO you should use a PUT call instead POST (as POST is not idempotent).

Also, as you are Putting a resource, you can use

PUT http://system
<device>
  <status>RESET</status>
</device>

or

 PUT http://system/status/reset

But I think the 1st one is "more restful", since you are putting a resource, while the second onde you just use the url.

Diego Dias
so you'd say that PUT is an UPDATE and POST is an INSERT (IBM instead of Sun definition)? See this: http://stackoverflow.com/questions/2447677/rest-verbs-which-convention-is-correct/2447740#2447740
ctacke
Not Really.If you think about CRUD, you can use this analogy, and it is correct to say that if you have an INSERT and an UPDATE, you should use POST and PUT, respectively.But the idempotence is more than that. Imagine there is a resource which you can only insert once on your DB and you should never change it. That's an insert and an idempotent action, so in this situation I think PUT would be used.
Diego Dias
PUT http://system/status/reset with an empty body just updates the resource to be empty. The first is the correct RESTful way.
Jan Algermissen
Also, differently from the link you posted. This use of PUT (idempotency and uploading a representation of a resource) is what the protocol of the Http methods say, not really a common use.http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods
Diego Dias
@Jan I agree with you. However as I don't know the exact use of the WS, I think that can also be used.
Diego Dias