Codeigniter 4 Restfull is the creation of Restfull API with the codeigniter 4 framework. Use is very simple and easy to use. And support with 4 types of security authentication ex. JWT, Basic, Key, Token
You can manage api using database or File configuration
follow Setup Configuration!
Now is Beta Version
- composer
composer create-project appkita/ci4restfull-starter@v1.0-BETA
cd ci4restfull-starter
composer update
-manual
- clone github
git@github.com:gunantos/ci4restfull-starter.git
- cd
ci4restful-starter
composer install
- Copy
env
to.env
and tailor for your app, specifically the baseURL, any database settings and Restfull setting.
or
- Open Folder
App/Config/Restfull
and edit
//you can set database of file
public $cekfrom = 'file'
//configuration user cek
public $user_config = [
'model' => 'UserModel', //model name or parameter if you using file
'username_coloumn'=>'email',
'password_coloumn'=>'password',
'key_coloumn' => 'apikey',
'path_coloumn'=>'path',
'block_coloumn'=>'isblock',
'whitelist_coloumn'=>'whitelist',
'blacklist_coloumn'=>'blacklist'
];
//if you using file $cekfrom
$UserModel = [
[
'email'=>'user@email.com',
'password'=>'password',
'apikey'=>'123123',
'isblock'=>false, //if you block return true
'whitelist'=>[], //add whitelist ip address
'blacklist'=>[], //add blacklist ip address
'path'=>'*' //use * for allow all access or array controllername_methodname
]
]
//Configuration your Header API KEY
public $haderKey = 'X-API-KEY';
//configuration data include on json token
$token_data = 'username';
- Create new Controller extends
RestfullApi
<?php
namespace App\Controllers;
class Home extends RestfullApi
{
protected $auth = ['digest', 'basic', 'key', 'token'] //if you using multi authentication on controler
/** or
* protected $aut = 'basic';
*/
$model = YourModelDB;
$format = 'json';
public function index {
return $this->respond(['status'=>200, 'data'=>$this->model->findAll());
}
public function show($id = null)
{
return $this->respond(['status'=>200, 'data'=>$this->model->find($id));
}
/**
* Create a new resource object, from "posted" parameters
*
* @return mixed
*/
public function create(){}
/**
* Return the editable properties of a resource object
*
* @param mixed $id
*
* @return mixed
*/
public function edit($id = null){}
/**
* Add or update a model resource, from "posted" properties
*
* @param mixed $id
*
* @return mixed
*/
public function update($id = null){}
/**
* Delete the designated resource object from the model
*
* @param mixed $id
*
* @return mixed
*/
public function delete($id = null){}
}
/**
* Delete the designated resource object from the model
*
* @param mixed $id
*
* @return mixed
*/
public function delete($id = null)
{
return $this->respond(['status'=>200, 'data'=>$this->model->delete($id)]);
}
}
- Run application with
spark
orhost
//spark
php spark serve
- acess api
http://localhost:8080
spark runhttp://localhost/yourapi/public
xamp or wamp
Please read the user guide for a better explanation of how CI4 works!
PHP version 7.3 or higher is required, with the following extensions installed:
Additionally, make sure that the following extensions are enabled in your PHP: