REST is not RPC. Unfortunately, this module is RPC.

From my understanding of the REST architecture style, the idea is that every object in your system is represented by a unique URL that you can manipulate. For example, in Drupal, an ideal REST server would let you do HTTP GET on:

http://drupal.example.com/rest/node/nid

to get an XML representation of the node. Then if you wanted to edit it, you would first GET it, modify it then do a HTTP PUT on the same URL to save it back again. You could create a new node by doing an HTTP POST on http://drupal.example.com/rest/node/

Obviously, to delete a node, you do HTTP DELETE on the same URL. REST is all about the URLs (really, URIs) representing state objects in your system. The URL represents some logical object (a node, a setting, etc.) not a method. HTTP methods are then used to manipulate the resource.

Zend's "rest server", which this module now relies on, is not REST. It's just a dressed up RPC-style interface using HTTP GET URLs and XML. I am not sure what they are thinking with it, but I suspect it's more marketing than anything else.

My recommendation would be to rethink the API architecture of this module so that it better matches other RESTful systems. Labeling it REST, when it isn't is not very helpful.

For some examples of RESTful APIs done well, take a look at Amazon S3, the ATOM publishing protocol (RFC 5023) or SIP's XCAP (RFC 4825). They're all reasonably well designed APIs that let you use tools like 'curl' to manipulate complex systems. Done well, a RESTful API can let you get away with doing things that one would never expect possible without a lot more legwork.

Comments

robloach’s picture

I'd completely endorse an implementation of this using your suggested implementation of it. I put this together pretty quickly for a client and haven't had much time since to make it the best it could be. Any patches would be awesome.

Having a look at the Flickr REST API, it looks like we have the same interface going. Their endpoint is actually the same as the REST Services' endpoint:

http://drupal.example.com/services/rest/?method=flickr.test.echo&name=value

As for how the Zend Framework manages its returns, I'm not sure how they compare to what Flickr responds with. It would be worth testing. Any thoughts?

xxvelcrar’s picture

I don't feel that flickr's "REST" API is REST either. One of the key things that differentiates a RESTful architecture from more common HTTP APIs is that the objects of the system are the URLs.

To make Flickr's API RESTful, I would put the API key in the HTTP header (all good HTTP libraries allow for this, so it isn't a limiting factor), and have things like:

http://flickr.example.com/restapi/USERNAME/userphotos/

for an XML feed of all the user's photos.

As far as rewriting this module to be more RESTful, keep an eye out for a large, API-breaking patch :-)

robloach’s picture

Title: This "REST server" isn't REST. » Remove Zend Framework for Better RESTful API
Priority: Normal » Critical

Looking forward to it! :-)

moshe weitzman’s picture

Status: Active » Needs review

Actually, I don't even think you are supposed to have 'restapi' in the URL. You just take actions on the main URL like http://flickr.example.com/USERNAME/userphotos?format=xml or somesuch.

I think it is very confusing that the json module is named for its return format whereas the XMLRPC module is named for its protocol and the REST module is just oddly named. I think the REST module ought to be named XML since thats its outut format. Its input protocol is just http but same for JSON.

robloach’s picture

Status: Needs review » Closed (duplicate)
kim.pepper’s picture

I aggree! Its good to see someone else who understands what REST actually means.

In other frameworks, I've used a file extension to signify the response type (e.g. http://flickr.example.com/{USERNAME}/photos.xml or http://flickr.example.com/{USERNAME}/sets/myset/photos.json)