1. Go to this page and download the library: Download meksiabdou/ci4-restful 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/ */
meksiabdou / ci4-restful example snippets
use CI4Restful\Helpers\RestServer;
class ApiController extends RestServer
{
public function index()
{
return $this->response_json(["id" => 1, "bar" => "foo" ]], true);
}
}
public function store($requestData=null) {
$this->db->insert('mytable', $requestData);
$id = $this->db->insert_id();
return $this->response->json(['id'=>$id], true , 201);
}
public function store($requestData=null) {
if(!$requestData) {
return $this->response->json([], false );
}
}
public $aliases = [
'cors' => \Fluent\Cors\Filters\CorsFilter::class,
// ...
];