How to send POST request to Phil Sturgeon's CodeIgniter RestServer How to send POST request to Phil Sturgeon's CodeIgniter RestServer codeigniter codeigniter

How to send POST request to Phil Sturgeon's CodeIgniter RestServer


Finally SOLVED this problem! It was my POST request in the RESTClient controller that is wrong. After doing some searching and lots of trying / changing the codes, this code works for me for POST request in my RESTClient controller :

$news_id = 12; //this is the id of the news that you want to edit$method = 'post';$params = array('news_id' => $news_id, 'news_title' => $this->input->post('news_title'), 'news_category' => $this->input->post('news_category') );$uri = 'newscontroller/news';$this->rest->format('application/json');$result = $this->rest->{$method}($uri, $params);if(isset($result->status) && $result->status == 'success')  {      $data['message'] ='News has been updated.';      $this->load->view('otherpageview',$data);}     else  {      $data['message'] ='Something has gone wrong';      $this->load->view('otherpageview',$data);} 

With a lot of help from this reference

I post this if anybody needs an example of the right POST request in RESTClient and RESTServer, because I find it hard to look for an example for POST request in RESTClient-Server*** by Phil Sturgeon.

I'm using :

  • RESTServer (philsturgeon) v.2.6.0
  • RESTClient (philsturgeon) v.2.1.0
  • cURL (philsturgeon) v.1.2.1
  • CodeIgniter v.2.0.3


There was a problem with the way the post was implemented. see issue on github and another issue on github.

You can either patch your code, or get the latest sources.

Basically you find the post function in the RestServer application/libraries/REST_Controller.php and if it does not look like the following then change it to:

public function post($key = NULL, $xss_clean = TRUE){    if ($key === NULL)    {        return $this->_post_args;    }    return array_key_exists($key, $this->_post_args) ? $this->_xss_clean($this->_post_args[$key], $xss_clean) : FALSE;}