moudarir / codeigniter-rest-api
A RESTful server implementation for CodeIgniter 3
Requires
- php: ^8.4
- ext-json: *
- firebase/php-jwt: ^7.0
- moudarir/helpers: ^1.7
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-07 01:11:18 UTC
README
A RESTful server implementation for CodeIgniter 3.
Table of contents
Requirements
- PHP 8.4+
- CodeIgniter 3.1.*.
Installation
This library uses Composer to be installed.
Run this command line (recommended) in the same path as your composer.json file:
composer require moudarir/codeigniter-rest-api
Or, In your composer.json file, add the following code in require section:
{
...
"require": {
...
"moudarir/codeigniter-rest-api": "^4.0"
},
...
}
And then run:
composer update
Configuration
To add on next release.
Important
Execute the dumping/queries.sql file to create the tables needed for the API to work properly.
Tables that will be created are client, client_limit and client_log.
You're now ready to begin using the library 👌.
Usage
Create the [your-project]/application/controllers/api/ApiRequests.php controller:
<?php defined('BASEPATH') || exit('No direct script access allowed'); use App\Models\Client\Client; use Moudarir\CIRestApi\ApiController; use Moudarir\CIRestApi\Exceptions\ApiException; use Moudarir\CIRestApi\ApiConfig; use Moudarir\Helpers\Datetime\DatetimeHelper; use Firebase\JWT\JWT; /** * @property ApiRequests */ class ApiRequests extends ApiController { /** * @throws ApiException */ public function __construct() { parent::__construct(ApiConfig::create( enableAuthentication: true, authenticationClassName: Client::class, authenticationJWTSecret: "YOUR_JWT_SECRET", authenticationJWTAlgo: "HS256", enableApiKey: true, )); } public function token(): void { $now = DatetimeHelper::now(); $this->response->ok([ 'data' => JWT::encode( [ 'iss' => base_url(), 'iat' => $now->getTimestamp(), 'exp' => $now->addMonths()->getTimestamp(), 'client_id' => $this->client->getId() ], $this->apiConfig->authenticationJWTSecret, $this->apiConfig->authenticationJWTAlgo ) ]); } }
Authentication methods
The Rest Server can be used with Basic or Bearer authorization type. However, it can be used without any authorization type (not secure).
✨ That's it!
Todo
- Improve documentation.