Extending Codeigniter for REST

August 4, 2009

I've recently been developing a little something in CodeIgniter that features an API that is as true as possible to the principles of REST. In order to do this, I had to extend the core CodeIgniter Input library to allow access to properly escaped values from DELETE or PUT input in the same way as you would normally access GET/POST input.

<?php
  function delete($index = '', $xss_clean = FALSE) {
    if (strtoupper($this->server('REQUEST_METHOD')) != 'DELETE') {
      return FALSE;
    }
    parse_str(file_get_contents&#40;"php://input"&#41;, $_DELETE);
    return $this->_fetch_from_array($_DELETE, $index, $xss_clean);
  }
?>

The code is pretty simple, and unfortunately does require file_get_contents until I can figure out an alternative way of accessing the input. The whole class can be downloaded, played with and forked from my GitHub account.