1. Go to this page and download the library: Download nueip/codeigniter-rest library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nueip / codeigniter-rest example snippets
class ApiController extends nueip\rest\Controller
{
public function index()
{
return $this->response->json(['bar'=>'foo']);
}
}
public function store($requestData=null) {
$this->db->insert('mytable', $requestData);
$id = $this->db->insert_id();
return $this->response->json(['id'=>$id], 201);
}
try {
throw new Exception("API forbidden", 403);
} catch (\Exception $e) {
// Pack data into a standard format
$data = $this->pack(['bar'=>'foo'], $e->getCode(), $e->getMessage());
return $this->response->json($data, $e->getCode());
}
public function index() {}
protected function store($requestData=null) {}
protected function show($resourceID) {}
protected function update($resourceID=null, $requestData=null) {}
protected function delete($resourceID=null, $requestData=null) {}