Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send DELETE request to phil sturgeon's - codeigniter-restserver

As the title says, I'm using Codeigniter with phil sturgeon - codeigniter-restserver framework.

I've followed the tutorial on Nettus and everything works fine Except when sending a DELETE request.

Code:

<?php
require(APPPATH.'libraries/REST_Controller.php');

class Client extends REST_Controller{

function user_get()
{
    $data = array('returned:'=> $this->get('id'));
    $this->response($data);
}

function user_post()
{
    $data = array('returned:'=> $this->post('id'));
    $this->response($data);
}

function user_put()
{
    $data = array('returned:'=> $this->put('id'));
    $this->response($data);
}

function user_delete()
{
    $data = array('returned from delete:'=> $this->delete('id'));
    $this->response($data);
}
}

I'm using a FF Addon called HTTP Resource test, to send the request but when i send a DELETE request with this URL: http://localhost/api/client/user/id/1, I get {"returned from delete:":false}

As a side note : I found this post and using the 'X-HTTP-Method-Override' header and sending it as a post request i was able to get the id, but I preffer a way where the client does not have to add this header.

like image 564
Tomer Avatar asked Jun 12 '12 13:06

Tomer


1 Answers

According the the HTTP spec DELETE cannot send parameters. It can have things in the URL, so you could change this to:

public function user_delete($id)
{
    $this->response(array(
        'returned from delete:' => $id,
    ));
}
like image 130
Phil Sturgeon Avatar answered Oct 14 '22 16:10

Phil Sturgeon