RESTp delete function provides a simplest way to delete the data from database by passing the data in form of associative array. You can easily delete a record using the DELETE method and by passing data needs to be deleted. DELETE APIs are primarily to delete existing resource. If you perform a `DELETE` request, the server deletes an entry in the database and tells you whether the delete is successful. In other words, a `DELETE` request performs an `UPDATE` operation. On success, it returns the number of records deleted.
Please note that if you are sending data as json format using json_encode function then you must specify the content type header ('Content-Type:application/json') as default content type is post array. Also, you must specify the where condition if you intend to delete a single resource else all resources will be deleted. You can pass where condition either in data array or in url.
// You can pass where condition as data or in url //Dummy data to delete. Please note the format of data //$data = array("where" => array('order_no,2222,"eq"')); //Option 1: Convert data array to json if you want to send data as json //$data = json_encode($data); //Option 2: else send data as post array. //$data = urldecode(http_build_query($data)); /****** curl code ****/ //init curl $ch = curl_init(); // URL to be called curl_setopt($ch, CURLOPT_URL, "http://pdocrud.com/RESTP/api/orders/49"); //set http headers - if you are sending as json data (i.e. option 1) else comment this curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); //set CURLOPT_CUSTOMREQUEST = DELETE to do a HTTP DELETE curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); //send post data curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //return as output instead of printing it curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //execute curl request $result = curl_exec($ch); //close curl connection curl_close($ch); //print result print_r($result);