users@jersey.java.net

Re: [Jersey] style question WRT REST principles

From: Craig McClanahan <craigmcc_at_gmail.com>
Date: Thu, 26 Aug 2010 16:05:58 -0700

On Thu, Aug 26, 2010 at 1:03 PM, PhuDuc Nguyen <duc.was.here_at_gmail.com>wrote:

> I often find myself in situations where I need to execute a method that
> does not belong with any of the CRUD operations. What if I just want to
> execute an action where no resource is being created, read, updated, or
> deleted. For example, what if I'm controlling something like a phone and I
> want to instruct it to call someone. If this were a SOAP service, I would
> just define my Java interface to have something like
>
> public boolean call(int phoneNumber);
>
> However, I'm a bit confused as how this translates into RESTful style. What
> then does the HTTP operation become? I'm certainly not deleting anything,
> not reading anything, not updating anything. You could make the argument
> that an "event" is being created...a "phone call event" is being created
> maybe? What then would the URI look like?
>
> http://<server>/phone/5551234
> with POST as the HTTP operation? Shouldn't that be the URI for creating a
> phone number? I'm trying to adhere to RESTful principles and I'm curious
> about good style. Would you define something like:
>
> http://<server>/phone/callevent/5551234
>
> In scenarios like this, I would think of doing a POST to "http://<server>/phone/5551234/call",
with the reasoning that the act of placing a call probably does create a
resource (an entry in the call log), even if that resource does not have a
URI you can use to retrieve it. Or, you might even think about exposing the
call log later with "GET http://<server>/phone/5551234/call/{callID}".
 Also, if you need to trigger other actions on a phone number, this approach
is also nicely extensible by changing the last path element.

Regardless of what URI pattern you choose, you should definitely *not* use a
GET verb for things like this, if they have side effects in the system.
 POST seems to be the best fit for RPC-ish situations like this.


> thanks in advance,
> PDNWPS
>
> Craig