Why I don't like REST for web application

Comments

angch's picture

Aliasing (aka demux), ala Rails.

Consider that:

$method /foo/12 HTTP/1.0

can be emulated and equivalent to

POST /foo/12 HTTP/1.0

_method=$method

This is similar to drupal's clean_url implementation of

http://example.com/foo/bar

being the same as:

http://example.com/index.php?q=foo/bar

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
    }
}