User login
Navigation
Recent blog posts
- Ubuntu mirrors up and improved!
- Google-jstemplate: Iterate object with unknown properties
- nginx https proxypass for php apps
- sugarcrm & memcache: Doing it Wrong
- subversion and https in Ubuntu Karmic
- Drupal: Views block delta converted to md5 hash
- Ubuntu Server install requires PAE
- Installing Drupal from command line
- Drupal: Handling form field weight through CCK
- minify javascript using Google Closure Compiler
angch's location
angch twitter
- angch: Heading to Brunei. Business class for a change.
- angch: tc qdisc htb activated on the mirror, and mirror reactivated. Hope nothing melts now.
- angch: Hmmm, tbf doesn't work as advertised. htb does. #qos #linux
- angch: @yoonkit me thinks #lucid is a much better tag than #lynx
- angch: Great, you broke the dc's net and they disconnected us. Running to tpm from shah alam
Why I don't like REST for web application

kamal — Thu, 14/08/2008 - 02:25
Just to document my thought before going to bed tonight. I've try to implement RESTful web application after get hooked with web.py few years ago. It end up with frustration. The REST concept is just ideal and I can't really say how much I like it. I'd even wrote a simple PHP dispatcher for that but the problem is the browser which only implement 2 HTTP methods for you to get around the application.
It's either POST or GET, unless you make the request through some XMLHTTP request (ajax ...).
Ideally, in a fully RESTful application:-
GET /customers
would return a list of customers.
POST /customer
would add the new resource customer and return the identifier or location of the new resource.
PUT /customer/20
would modify customer resource with ID 20.
DELETE /customer/20
would delete customer resource with ID 20.
With limitation of the browser, implementation is not that easy. You can't directly DELETE a resource since there's no way the browser can issue that request. Most of the workaround I saw is to create another resource, some kind of Deleter resource so you can POST to that (another workaround) to delete the resource. You end up having something like:-
class Customer {
function GET($resource_id = Null) {
}
function POST() {
// add new customer
}
}
class CustomerUpdater {
function GET($id) {
// display the edit form
}
function POST($id) {
// modify the customer
}
}
class CustomerDeleter {
function GET($id) {
// display the confirmation form
}
function POST($id) {
// delete the customer
}
}
Instead of:-
class Customer {
function GET($resource_id = Null) {
}
function POST() {
// add new customer
}
function PUT($id) {
// modify customer
}
function DELETE($id) {
// delete customer
}
}
We start to see how it getting ugly. There's maybe other workaround but what I can say, when you start doing all these things it's not RESTful anymore.
There another PHP project called tonic that try to implement a RESTful framework but I guess the development is now stalled. Pronto also trying doing the same though not really RESTful.

Aliasing (aka demux), ala Rails.
angch — Thu, 14/08/2008 - 17:27Consider that:
can be emulated and equivalent to
This is similar to drupal's clean_url implementation of
being the same as:
In code, it becomes:
class Customer { function GET($resource_id = Null) { } // POST is a demux (yeah, I was into electronics) function POST() { if (isset($POST['_method']) && is_valid_emulated_method($POST['_method'])) { $method = $POST['_method']; return $this->$method(get_emulated_param()); } return $this->_POST(); } // Original POST operation function _POST() { // add new customer } function PUT($id) { // modify customer } function DELETE($id) { // delete customer } }