{"id":14987272,"url":"https://github.com/ctechhindi/codeigniter-api-controller","last_synced_at":"2025-08-20T12:30:48.369Z","repository":{"id":56959931,"uuid":"128528120","full_name":"ctechhindi/CodeIgniter-API-Controller","owner":"ctechhindi","description":"CodeIgniter Restful API Controller - Easily build REST API with Token Authorization","archived":false,"fork":false,"pushed_at":"2020-05-05T19:25:56.000Z","size":596,"stargazers_count":68,"open_issues_count":3,"forks_count":50,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-12-09T05:34:26.131Z","etag":null,"topics":["api","codeigniter","codeigniter-library","php","php-jwt","rest","rest-api"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ctechhindi.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-07T12:55:39.000Z","updated_at":"2024-11-15T23:47:32.000Z","dependencies_parsed_at":"2022-08-21T05:10:16.148Z","dependency_job_id":null,"html_url":"https://github.com/ctechhindi/CodeIgniter-API-Controller","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctechhindi%2FCodeIgniter-API-Controller","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctechhindi%2FCodeIgniter-API-Controller/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctechhindi%2FCodeIgniter-API-Controller/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctechhindi%2FCodeIgniter-API-Controller/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ctechhindi","download_url":"https://codeload.github.com/ctechhindi/CodeIgniter-API-Controller/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230423559,"owners_count":18223435,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","codeigniter","codeigniter-library","php","php-jwt","rest","rest-api"],"created_at":"2024-09-24T14:14:21.740Z","updated_at":"2024-12-19T11:11:13.789Z","avatar_url":"https://github.com/ctechhindi.png","language":"PHP","readme":"# CodeIgniter API Controller v.1.1.7\n\nThis extension is powered by `Jeevan Lal`.\n\n## Files\n\n[API Documentation](https://github.com/jeevan15498/CodeIgniter-API-Controller#documentation)\n\n* `\\application\\libraries\\API_Controller.php`\n* `\\application\\helpers\\api_helper.php`\n* `\\application\\config\\api.php`\n\n[Token Documentation](token.md)\n\n* `\\application\\libraries\\Authorization_Token.php`\n* `\\application\\config\\jwt.php`\n* [PHP-JWT](https://github.com/firebase/php-jwt) Library `\\application\\third_party\\php-jwt\\`\n\n## Installation\n\nYou can install this project into your PC using [composer]().\n\nThe recommended way to install composer packages is:\n\n```\ncomposer require ctechhindi/codeigniter-api:dev-master --prefer-source\n```\n\n## Requirements\n\n1. PHP 5.4 or greater\n2. CodeIgniter 3.0+\n\nNote: The library is used in CodeIgniter v3.8 and PHP 5.6.8.\n\n## DEMO\n\n\u003e http://codeigniter-api.speedtyping.in/api/user/login\n\nSimple API\n\n```php\nheader(\"Access-Control-Allow-Origin: *\");\n\n// API Configuration\n$this-\u003e_apiConfig([\n    /**\n     * By Default Request Method `GET`\n     */\n    'methods' =\u003e ['POST'], // 'GET', 'OPTIONS'\n\n    /**\n     * Number limit, type limit, time limit (last minute)\n     */\n    'limit' =\u003e [5, 'ip', 'everyday'],\n\n    /**\n     * type :: ['header', 'get', 'post']\n     * key  :: ['table : Check Key in Database', 'key']\n     */\n    'key' =\u003e ['POST', 'string_key' ], // type, {key}|table (by default)\n]);\n\n// return data\n$this-\u003eapi_return(\n    [\n        'status' =\u003e true,\n        \"result\" =\u003e \"Return API Response\",\n    ],\n200);\n```\n\n## Documentation\n\n### Setup API Request Methods\n\n* This Function by default request method `GET`\n\n```php\n$this-\u003e_APIConfig();\n```\n\n* Set `API Request` Method `POST, GET, ..`\n\n```php\n$this-\u003e_APIConfig([\n    'methods' =\u003e ['POST', 'GET'],\n]);\n```\n---\n\n### Use API Limit\n\nBefore using the limit in API, we need to load the codeigniter `database library`.\nYou can also load the database library in the autoload config `config/autoload.php` file.\n\nAfter database library loaded, database must be set in database config file `config/database.php`.\n\nAfter creating and setting up a database, we need to create a table for API Limit `[api_limit]` in the database. like this.\n\n```sql\nCREATE TABLE `api_limit` (\n    `id` INT NOT NULL AUTO_INCREMENT ,  \n    `user_id` INT NULL DEFAULT NULL ,  \n    `uri` VARCHAR(200) NOT NULL ,  \n    `class` VARCHAR(200) NOT NULL ,  \n    `method` VARCHAR(200) NOT NULL ,  \n    `ip_address` VARCHAR(50) NOT NULL ,  \n    `time` TEXT NOT NULL ,    PRIMARY KEY  (`id`)\n) ENGINE = InnoDB;\n```\n\nThe name of the database table of api limit is `api_limit` by default. Which we can change through the API configuration file `[config/api.php]`. like this.\n\n```php\n/**\n * API Limit database table name\n */\n$config['api_limit_table_name'] = 'api_limit';\n\n/**\n * Set API Timezone \n */\n$config['api_timezone'] = 'Asia/Kolkata';\n```\nNow we can use API Limit Method.\n\nThus this API can be run only 10 times in 5 minutes. It on `IP address`.\n\n```php\n/**\n * API Limit\n * ----------------------------------\n * @param: {int} API limit Number\n * @param: {string} API limit Type (IP)\n * @param: {int} API limit Time [minute]\n */\n\n$this-\u003e_APIConfig([\n    // number limit, type limit, time limit (last minute)\n    'limit' =\u003e [10, 'ip', 5] \n]);\n```\n\nAt API limit `time argument` we can also use `everyday` which will follow the api limit per day. On the same API address\n\n```php\n/**\n * API Limit\n * ----------------------------------\n * @param: {int} API limit Number\n * @param: {string} API limit Type (IP)\n * @param: {string} API limit [everyday]\n */\n\n$this-\u003e_APIConfig([\n    // number limit, type limit, everyday\n    'limit' =\u003e [10, 'ip', 'everyday'] \n]);\n```\n---\n### Use API Key without Database\n\nWe can set the API key in the Request Header. by default, the name of the header is `X-API-K`, which we can change in the API config file `[config/api.php]`. like this \n\n```php\n/**\n * API Key Header Name\n */\n$config['api_key_header_name'] = 'X-API-KEY';\n```\nUse this code in your API Controller file.\n\n```php\n/**\n * Use API Key without Database\n * ---------------------------------------------------------\n * @param: {string} Types\n * @param: {string} API Key\n */\n\n$this-\u003e_APIConfig([\n    'key' =\u003e ['header', 'Set API Key'],\n]);\n```\n---\n\n### Use API Key with Database\n\nWe can also check the API key by `databases`. For this, we need to first create `api_keys` table in MySQL. like this \n\n```sql\nCREATE TABLE `api_keys` ( \n    `id` INT NOT NULL AUTO_INCREMENT ,  \n    `api_key` VARCHAR(50) NOT NULL ,  \n    `controller` VARCHAR(50) NOT NULL ,  \n    `date_created` DATE NULL DEFAULT NULL ,  \n    `date_modified` DATE NULL DEFAULT NULL ,    PRIMARY KEY  (`id`)\n) ENGINE = InnoDB;\n```\n\nThe name of the database table of API Keys is `api_keys` by default. Which we can change through the API configuration file `[config/api.php]`. like this.\n\n```php\n/**\n * API Keys Database Table Name \n */\n$config['api_keys_table_name'] = 'api_keys';\n```\n\nSet API keys in `api_keys` database table And Use this code in your API Controller file. \n\n```php\n/**\n * API Key\n * ---------------------------------------------------------\n * @param: {string} Types\n * @param: {string} [table]\n */\n$this-\u003e_APIConfig([\n    // 'key' =\u003e ['header', 'table'],\n    'key' =\u003e ['header'], \n]);\n```\n---\n\n### Use Custom Function in API Key\n\n```php\n/**\n * API Key\n * ---------------------------------------------------------\n * @param: {string} Types\n * @param: [function] return api key\n */\n$this-\u003e_APIConfig([\n    'key' =\u003e ['header', $this-\u003ekey() ],\n]);\n\n// This is Custom function and return api key\nprivate function key() {\n    return 1452;\n}\n```\n---\n\n### Add Custom Data in API Responses\n\nIn response to the API, we can also add custom data to something like this.\n\n\n```php\n$this-\u003e_APIConfig([\n    'key' =\u003e ['header'],\n    'data' =\u003e [ 'is_login' =\u003e false ] // custom data\n]);\n```\n\nAPI Output :: \n\n```json\n{\n    \"status\": false,\n    \"error\": \"API Key Header Required\",\n    \"is_login\": false\n}\n```\n---\n\n### API Return Data\n\nThis method is used to return data to api in which the response data is `first` and the `second` request status code.\n\n```php\n/**\n * Return API Response\n * ---------------------------------------------------------\n * @param: API Data\n * @param: Request Status Code\n */\n$this-\u003eapi_return(data, status_code);\n```\n\n#### Request Status Code List\n\n| Status Code| Status Text |\n| ---------- | ----------- |\n| 200 | OK |\n| 401 | UNAUTHORIZED |\n| 404 | NOT FOUND |\n| 408 | Request Timeout |\n| 400 | BAD REQUEST |\n| 405 | Method Not Allowed |\n\n\n## Using the Config file in the API key\n\n1. Create config file `\\application\\config\\api_keys.php`\n2. Use in API Controller like this\n\n```php\n// load API Keys config file\n$this-\u003eload-\u003econfig('api_keys');\n\n$this-\u003e_APIConfig([\n    'key' =\u003e ['post', $this-\u003econfig-\u003eitem('controller/api key name')],\n]);\n```\n\n## Reporting Issues\n\nIf you have a problem with this plugin or found any bug, please open an issue on [GitHub](https://github.com/jeevan15498/CodeIgniter-API-Controller/issues).\n\n# License\nCodeIgniter API Controller is licensed under [MIT](http://www.opensource.org/licenses/MIT)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fctechhindi%2Fcodeigniter-api-controller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fctechhindi%2Fcodeigniter-api-controller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fctechhindi%2Fcodeigniter-api-controller/lists"}