I am implementing my own API. I’m following the tutorial here. Even though I follow it I had a hard time to make my API working.
I didn’t get what is the difference with CodeIgniter REST Server and CodeIgniter REST Client. If someone explain it to me it would be a big help.
And now my real problem is: I have a controller below and I extends the REST_Controller.php which was written in the tutorial.
class Call extends REST_Controller
{
public function news()
{
// initialize you setting
$config = array(
'server' => 'localhost'
);
$this->rest->initialize($config);
// Set method of sending data
$method = 'post';
// create your param data
$param = array(
'id' => '1',
'name' => 'test'
);
// url where you want to send your param data.
$uri = 'http://192.90.123.908/api_v1/index.php';
// set format you sending data
$this->rest->format('application/json');
// send your param data to given url using this
$result = $this->rest->{$method}($uri, $params);
$data=array(
'id' => '1',
'name' => 'test'
);
print_r($data);
}
}
What I expected is when I access this url http://localhost/website/index.php/call/news
. I will get a JSON response. But what I get is
{"status":false,"error":"Unknown method"}
. I can’t find what is wrong.