├── .github ├── FUNDING.yml └── workflows │ └── php.yml ├── .gitignore ├── LICENSE ├── README.md ├── app ├── .htaccess ├── Common.php ├── Config │ ├── App.php │ ├── Autoload.php │ ├── Boot │ │ ├── development.php │ │ ├── production.php │ │ └── testing.php │ ├── Cache.php │ ├── Constants.php │ ├── ContentSecurityPolicy.php │ ├── Database.php │ ├── DocTypes.php │ ├── Email.php │ ├── Encryption.php │ ├── Events.php │ ├── Exceptions.php │ ├── Filters.php │ ├── ForeignCharacters.php │ ├── Format.php │ ├── Generators.php │ ├── Honeypot.php │ ├── Images.php │ ├── Kint.php │ ├── Logger.php │ ├── Migrations.php │ ├── Mimes.php │ ├── Modules.php │ ├── Pager.php │ ├── Paths.php │ ├── Restfull.php │ ├── RestfullAutoList.php │ ├── Routes.php │ ├── Security.php │ ├── Services.php │ ├── Toolbar.php │ ├── UserAgents.php │ ├── Validation.php │ └── View.php ├── Controllers │ └── Home.php ├── Database │ ├── Migrations │ │ └── .gitkeep │ └── Seeds │ │ └── .gitkeep ├── Filters │ ├── .gitkeep │ └── Cors.php ├── Helpers │ └── .gitkeep ├── Language │ ├── .gitkeep │ └── en │ │ └── Validation.php ├── Libraries │ └── .gitkeep ├── Models │ ├── .gitkeep │ ├── RestLogModel.php │ ├── UserModel.php │ └── WebhookLogModel.php ├── Restfull │ ├── Auth │ │ ├── BaseAuth.php │ │ └── Cek.php │ ├── AutomaticAPIFunction.php │ ├── BaseController.php │ ├── Cache │ │ ├── CacheAPI.php │ │ └── CacheUSER.php │ ├── ErrorOutput.php │ ├── Logging.php │ ├── RestfullApi.php │ └── Routes.php ├── ThirdParty │ └── .gitkeep ├── Views │ ├── errors │ │ ├── cli │ │ │ ├── error_404.php │ │ │ ├── error_exception.php │ │ │ └── production.php │ │ └── html │ │ │ ├── debug.css │ │ │ ├── debug.js │ │ │ ├── error_404.php │ │ │ ├── error_exception.php │ │ │ └── production.php │ └── welcome_message.php └── index.html ├── builds ├── composer.json ├── composer.lock ├── env ├── phpunit.xml.dist ├── public ├── .htaccess ├── favicon.ico ├── index.php └── robots.txt ├── spark ├── tests ├── README.md ├── _support │ ├── Database │ │ ├── Migrations │ │ │ └── 2020-02-22-222222_example_migration.php │ │ └── Seeds │ │ │ └── ExampleSeeder.php │ ├── DatabaseTestCase.php │ ├── Libraries │ │ └── ConfigReader.php │ ├── Models │ │ └── ExampleModel.php │ └── SessionTestCase.php ├── database │ └── ExampleDatabaseTest.php ├── session │ └── ExampleSessionTest.php └── unit │ └── HealthTest.php └── writable ├── .htaccess ├── cache └── index.html ├── logs └── index.html ├── session └── index.html └── uploads └── index.html /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: ['https://sponsor.app-kita.net'] 13 | -------------------------------------------------------------------------------- /.github/workflows/php.yml: -------------------------------------------------------------------------------- 1 | name: PHP Composer 2 | on: 3 | push: 4 | branches: [ main ] 5 | pull_request: 6 | branches: [ main ] 7 | 8 | jobs: 9 | build: 10 | 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | 16 | - name: Validate composer.json and composer.lock 17 | run: composer validate --strict 18 | 19 | - name: Cache Composer packages 20 | id: composer-cache 21 | uses: actions/cache@v2 22 | with: 23 | path: vendor 24 | key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} 25 | restore-keys: | 26 | ${{ runner.os }}-php- 27 | 28 | - name: Install dependencies 29 | run: composer install --prefer-dist --no-progress 30 | 31 | # Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit" 32 | # Docs: https://getcomposer.org/doc/articles/scripts.md 33 | 34 | # - name: Run test suite 35 | # run: composer run-script test 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #------------------------- 2 | # Operating Specific Junk Files 3 | #------------------------- 4 | .env 5 | 6 | # OS X 7 | .DS_Store 8 | .AppleDouble 9 | .LSOverride 10 | 11 | # OS X Thumbnails 12 | ._* 13 | 14 | # Windows image file caches 15 | Thumbs.db 16 | ehthumbs.db 17 | Desktop.ini 18 | 19 | # Recycle Bin used on file shares 20 | $RECYCLE.BIN/ 21 | 22 | # Windows Installer files 23 | *.cab 24 | *.msi 25 | *.msm 26 | *.msp 27 | 28 | # Windows shortcuts 29 | *.lnk 30 | 31 | # Linux 32 | *~ 33 | 34 | # KDE directory preferences 35 | .directory 36 | 37 | # Linux trash folder which might appear on any partition or disk 38 | .Trash-* 39 | 40 | #------------------------- 41 | # Environment Files 42 | #------------------------- 43 | # These should never be under version control, 44 | # as it poses a security risk. 45 | .env 46 | .vagrant 47 | Vagrantfile 48 | 49 | #------------------------- 50 | # Temporary Files 51 | #------------------------- 52 | writable/cache/* 53 | !writable/cache/index.html 54 | 55 | writable/logs/* 56 | !writable/logs/index.html 57 | 58 | writable/session/* 59 | !writable/session/index.html 60 | 61 | writable/uploads/* 62 | !writable/uploads/index.html 63 | 64 | writable/debugbar/* 65 | 66 | php_errors.log 67 | 68 | #------------------------- 69 | # User Guide Temp Files 70 | #------------------------- 71 | user_guide_src/build/* 72 | user_guide_src/cilexer/build/* 73 | user_guide_src/cilexer/dist/* 74 | user_guide_src/cilexer/pycilexer.egg-info/* 75 | 76 | #------------------------- 77 | # Test Files 78 | #------------------------- 79 | tests/coverage* 80 | 81 | # Don't save phpunit under version control. 82 | phpunit 83 | 84 | #------------------------- 85 | # Composer 86 | #------------------------- 87 | vendor/ 88 | 89 | #------------------------- 90 | # IDE / Development Files 91 | #------------------------- 92 | 93 | # Modules Testing 94 | _modules/* 95 | 96 | # phpenv local config 97 | .php-version 98 | 99 | # Jetbrains editors (PHPStorm, etc) 100 | .idea/ 101 | *.iml 102 | 103 | # Netbeans 104 | nbproject/ 105 | build/ 106 | nbbuild/ 107 | dist/ 108 | nbdist/ 109 | nbactions.xml 110 | nb-configuration.xml 111 | .nb-gradle/ 112 | 113 | # Sublime Text 114 | *.tmlanguage.cache 115 | *.tmPreferences.cache 116 | *.stTheme.cache 117 | *.sublime-workspace 118 | *.sublime-project 119 | .phpintel 120 | /api/ 121 | 122 | # Visual Studio Code 123 | .vscode/ 124 | 125 | /results/ 126 | /phpunit*.xml 127 | /.phpunit.*.cache 128 | 129 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2019 British Columbia Institute of Technology 4 | Copyright (c) 2019-2021 CodeIgniter Foundation 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | [![PHP Composer](https://github.com/gunantos/ci4restfull-starter/actions/workflows/php.yml/badge.svg)](https://github.com/gunantos/ci4restfull-starter/actions/workflows/php.yml) 3 | ![Discord](https://img.shields.io/discord/846036920811126844?style=plastic) 4 | [![GitHub issues](https://img.shields.io/github/issues/gunantos/ci4restfull-starter)](https://github.com/gunantos/ci4restfull-starter/issues) 5 | [![GitHub license](https://img.shields.io/github/license/gunantos/ci4restfull-starter)](https://github.com/gunantos/ci4restfull-starter/blob/main/LICENSE)
6 |
7 | # CodeIgniter 4 Restfull API Application Starter 8 | 9 | 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 10 | 11 | You can manage api using database or File configuration 12 | 13 | follow Setup Configuration! 14 | 15 | ## Chat 16 | [Discord](https://discord.gg/bXUWCSaw) 17 | 18 | 19 | ## Installation & updates 20 | 21 | - composer 22 | 23 | ```sh 24 | composer create-project appkita/ci4restfull-starter 25 | cd ci4restfull-starter 26 | composer update 27 | ``` 28 | 29 | -manual 30 | 31 | 1. Download latest release from `https://github.com/gunantos/ci4restfull-starter/releases` 32 | 2. extract to public_html 33 | 3. `composer install` 34 | 35 | ## Setup 36 | 37 | - Copy `env` to `.env` and tailor for your app, specifically the baseURL, any database settings and Restfull setting. 38 | 39 | `or` 40 | 41 | - Open Folder `App/Config/Restfull` and edit 42 | 43 | ```php 44 | //you can set database of file 45 | public $cekfrom = 'file' 46 | 47 | //configuration user cek 48 | public $user_config = [ 49 | 'model' => 'UserModel', //model name or parameter if you using file 50 | 'username_coloumn'=>'email', 51 | 'password_coloumn'=>'password', 52 | 'key_coloumn' => 'apikey', 53 | 'path_coloumn'=>'path', 54 | 'block_coloumn'=>'isblock', 55 | 'whitelist_coloumn'=>'whitelist', 56 | 'blacklist_coloumn'=>'blacklist' 57 | ]; 58 | 59 | //if you using file $cekfrom 60 | $UserModel = [ 61 | [ 62 | 'email'=>'user@email.com', 63 | 'password'=>'password', 64 | 'apikey'=>'123123', 65 | 'isblock'=>false, //if you block return true 66 | 'whitelist'=>[], //add whitelist ip address 67 | 'blacklist'=>[], //add blacklist ip address 68 | 'path'=>'*' //use * for allow all access or array controllername_methodname 69 | ] 70 | ] 71 | 72 | //Configuration your Header API KEY 73 | public $haderKey = 'X-API-KEY'; 74 | 75 | /** 76 | * @var array $allowed_key_parameter 77 | * if you API KEY allowed get from parameter GET, POST, or JSON 78 | */ 79 | public $allowed_key_parameter = ['get', 'post', 'json']; 80 | //configuration data include on json token 81 | $token_data = 'username'; 82 | 83 | public $allowed_format = ['json', 'xml', 'csv']; 84 | 85 | /** 86 | * @var string $default_format 87 | */ 88 | public $default_format = 'json'; 89 | 90 | ``` 91 | 92 | - Create new Controller extends `RestfullApi` 93 | 94 | ```php 95 | model = new UserModel(); 111 | } 112 | public function index() 113 | { 114 | return $this->respond(['status'=>true, 'data'=>$this->model->findAll()]); 115 | } 116 | 117 | public function show($id = null) 118 | { 119 | return $this->respond(['status'=>true, 'data'=>$this->model->find($id)]); 120 | } 121 | 122 | public function create() { 123 | die('create '); 124 | } 125 | 126 | public function update($id = null) { 127 | die('update '. $id); 128 | } 129 | 130 | public function deleted($id = null) { 131 | die('deleted '. $id); 132 | } 133 | } 134 | 135 | ``` 136 | 137 | - Run application with `spark` or `host` 138 | 139 | ```sh 140 | //spark 141 | php spark serve 142 | ``` 143 | 144 | - acess api 145 | `http://localhost:8080` spark run 146 | `http://localhost/yourapi/public` xamp or wamp 147 | 148 | ## Important 149 | 150 | **Please** read the user guide of [Codeigniter 4](https://codeigniter.com/user_guide/) 151 | 152 | # Sponsor 153 | 154 | [Pay Coffe](https://sponsor.app-kita.net) 155 | -------------------------------------------------------------------------------- /app/.htaccess: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gunantos/ci4restfull-starter/b9599f8f1d0fc4158e6ff0a526b190fd95d348e3/app/.htaccess -------------------------------------------------------------------------------- /app/Common.php: -------------------------------------------------------------------------------- 1 | SYSTEMPATH, 37 | * 'App' => APPPATH 38 | * ]; 39 | * 40 | * @var array 41 | */ 42 | public $psr4 = [ 43 | APP_NAMESPACE => APPPATH, // For custom app namespace 44 | 'Config' => APPPATH . 'Config', 45 | 'Appkita\\CI4Restfull' => APPPATH .'Restfull', 46 | 'Appkita\CI4Restfull\Cache' => APPPATH .'Restfull' 47 | ]; 48 | 49 | /** 50 | * ------------------------------------------------------------------- 51 | * Class Map 52 | * ------------------------------------------------------------------- 53 | * The class map provides a map of class names and their exact 54 | * location on the drive. Classes loaded in this manner will have 55 | * slightly faster performance because they will not have to be 56 | * searched for within one or more directories as they would if they 57 | * were being autoloaded through a namespace. 58 | * 59 | * Prototype: 60 | * 61 | * $classmap = [ 62 | * 'MyClass' => '/path/to/class/file.php' 63 | * ]; 64 | * 65 | * @var array 66 | */ 67 | public $classmap = [ 68 | 'Appkita\\CI4Restfull\\RestfullApi' => APPPATH .'Restfull/RestfullApi.php', 69 | 'Appkita\\CI4Restfull\\Auth' => APPPATH .'Restfull/Auth.php', 70 | 'Appkita\\CI4Restfull\\ErrorOutput' => APPPATH .'Restfull/ErrorOutput.php', 71 | 'Appkita\\CI4Restfull\\Cache\CacheUSER' => APPPATH .'Restfull/Cache/CacheAPI.php', 72 | 'Appkita\\CI4Restfull\\Cache\CacheAPI' => APPPATH .'Restfull/Cache/CacheUSER.php' 73 | ]; 74 | } 75 | -------------------------------------------------------------------------------- /app/Config/Boot/development.php: -------------------------------------------------------------------------------- 1 | 93 | */ 94 | public $file = [ 95 | 'storePath' => WRITEPATH . 'cache/', 96 | 'mode' => 0640, 97 | ]; 98 | 99 | /** 100 | * ------------------------------------------------------------------------- 101 | * Memcached settings 102 | * ------------------------------------------------------------------------- 103 | * Your Memcached servers can be specified below, if you are using 104 | * the Memcached drivers. 105 | * 106 | * @see https://codeigniter.com/user_guide/libraries/caching.html#memcached 107 | * 108 | * @var array 109 | */ 110 | public $memcached = [ 111 | 'host' => '127.0.0.1', 112 | 'port' => 11211, 113 | 'weight' => 1, 114 | 'raw' => false, 115 | ]; 116 | 117 | /** 118 | * ------------------------------------------------------------------------- 119 | * Redis settings 120 | * ------------------------------------------------------------------------- 121 | * Your Redis server can be specified below, if you are using 122 | * the Redis or Predis drivers. 123 | * 124 | * @var array 125 | */ 126 | public $redis = [ 127 | 'host' => '127.0.0.1', 128 | 'password' => null, 129 | 'port' => 6379, 130 | 'timeout' => 0, 131 | 'database' => 0, 132 | ]; 133 | 134 | /** 135 | * -------------------------------------------------------------------------- 136 | * Available Cache Handlers 137 | * -------------------------------------------------------------------------- 138 | * 139 | * This is an array of cache engine alias' and class names. Only engines 140 | * that are listed here are allowed to be used. 141 | * 142 | * @var array 143 | */ 144 | public $validHandlers = [ 145 | 'dummy' => DummyHandler::class, 146 | 'file' => FileHandler::class, 147 | 'memcached' => MemcachedHandler::class, 148 | 'predis' => PredisHandler::class, 149 | 'redis' => RedisHandler::class, 150 | 'wincache' => WincacheHandler::class, 151 | ]; 152 | } 153 | -------------------------------------------------------------------------------- /app/Config/Constants.php: -------------------------------------------------------------------------------- 1 | ` element. 81 | * 82 | * Will default to self if not overridden 83 | * 84 | * @var string|string[]|null 85 | */ 86 | public $baseURI = null; 87 | 88 | /** 89 | * Lists the URLs for workers and embedded frame contents 90 | * 91 | * @var string|string[] 92 | */ 93 | public $childSrc = 'self'; 94 | 95 | /** 96 | * Limits the origins that you can connect to (via XHR, 97 | * WebSockets, and EventSource). 98 | * 99 | * @var string|string[] 100 | */ 101 | public $connectSrc = 'self'; 102 | 103 | /** 104 | * Specifies the origins that can serve web fonts. 105 | * 106 | * @var string|string[] 107 | */ 108 | public $fontSrc = null; 109 | 110 | /** 111 | * Lists valid endpoints for submission from `
` tags. 112 | * 113 | * @var string|string[] 114 | */ 115 | public $formAction = 'self'; 116 | 117 | /** 118 | * Specifies the sources that can embed the current page. 119 | * This directive applies to ``, `