[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-8365":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":15,"stars30d":17,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":18,"rankGlobal":10,"rankLanguage":10,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":20,"hasPages":20,"topics":22,"createdAt":10,"pushedAt":10,"updatedAt":23,"readmeContent":24,"aiSummary":25,"trendingCount":16,"starSnapshotCount":16,"syncStatus":26,"lastSyncTime":27,"discoverSource":28},8365,"codeigniter-restserver","chriskacerguis\u002Fcodeigniter-restserver","chriskacerguis","A fully RESTful server implementation for CodeIgniter using one library, one config file and one controller.","",null,"PHP",4877,2790,399,1,0,3,32,"MIT License",false,"main",[],"2026-06-12 02:01:52","# CodeIgniter RestServer\n\nA fully RESTful server implementation for CodeIgniter 3 using one library, one config file and one controller.\n\n> [!IMPORTANT]\n> I have published the first \"beta\" of codeigniter-restserver 4.  See the \"development\" branch.  Please be sure to note the system requirments.\n\n## Requirements\n\n- PHP 7.2 or greater\n- CodeIgniter 3.1.11+\n\n## Installation\n\n```sh\ncomposer require chriskacerguis\u002Fcodeigniter-restserver\n```\n\n## Usage\n\nCodeIgniter Rest Server is available on [Packagist](https:\u002F\u002Fpackagist.org\u002Fpackages\u002Fchriskacerguis\u002Fcodeigniter-restserver) (using semantic versioning), and installation via composer is the recommended way to install Codeigniter Rest Server. Just add this line to your `composer.json` file:\n\n```json\n\"chriskacerguis\u002Fcodeigniter-restserver\": \"^3.1\"\n```\n\nor run\n\n```sh\ncomposer require chriskacerguis\u002Fcodeigniter-restserver\n```\n\nNote that you will need to copy `rest.php` to your `config` directory (e.g. `application\u002Fconfig`)\n\nStep 1: Add this to your controller (should be before any of your code)\n\n```php\nuse chriskacerguis\\RestServer\\RestController;\n```\n\nStep 2: Extend your controller\n\n```php\nclass Example extends RestController\n```\n\n## Basic GET example\n\nHere is a basic example. This controller, which should be saved as `Api.php`, can be called in two ways:\n\n* `http:\u002F\u002Fdomain\u002Fapi\u002Fusers\u002F` will return the list of all users\n* `http:\u002F\u002Fdomain\u002Fapi\u002Fusers\u002Fid\u002F1` will only return information about the user with id = 1\n\n```php\n\u003C?php\ndefined('BASEPATH') OR exit('No direct script access allowed');\n\nuse chriskacerguis\\RestServer\\RestController;\n\nclass Api extends RestController {\n\n    function __construct()\n    {\n        \u002F\u002F Construct the parent class\n        parent::__construct();\n    }\n\n    public function users_get()\n    {\n        \u002F\u002F Users from a data store e.g. database\n        $users = [\n            ['id' => 0, 'name' => 'John', 'email' => 'john@example.com'],\n            ['id' => 1, 'name' => 'Jim', 'email' => 'jim@example.com'],\n        ];\n\n        $id = $this->get( 'id' );\n\n        if ( $id === null )\n        {\n            \u002F\u002F Check if the users data store contains users\n            if ( $users )\n            {\n                \u002F\u002F Set the response and exit\n                $this->response( $users, 200 );\n            }\n            else\n            {\n                \u002F\u002F Set the response and exit\n                $this->response( [\n                    'status' => false,\n                    'message' => 'No users were found'\n                ], 404 );\n            }\n        }\n        else\n        {\n            if ( array_key_exists( $id, $users ) )\n            {\n                $this->response( $users[$id], 200 );\n            }\n            else\n            {\n                $this->response( [\n                    'status' => false,\n                    'message' => 'No such user found'\n                ], 404 );\n            }\n        }\n    }\n}\n```\n\n## Extending supported formats\n\nIf you need to be able to support more formats for replies, you can extend the\n`Format` class to add the required `to_...` methods\n\n1. Extend the `RestController` class (in `libraries\u002FMY_REST_Controller.php`)\n```php\n\u003C?php\n\nuse chriskacerguis\\RestServer\\RestController;\n\nclass MY_REST_Controller extends RestController\n{\n    public function __construct()\n    {\n        parent::__construct();\n        \u002F\u002F This can be the library's chriskacerguis\\RestServer\\Format\n        \u002F\u002F or your own custom overloaded Format class (see bellow)\n        $this->format = new Format();\n    }\n}\n```\n\n2. Extend the `Format` class (can be created as a CodeIgniter library in `libraries\u002FFormat.php`).\nFollowing is an example to add support for PDF output\n\n```php\n\u003C?php\n\nuse chriskacerguis\\RestServer\\Format as RestServerFormat;\n\nclass Format extends RestServerFormat\n{\n    public function to_pdf($data = null)\n    {\n        if ($data === null && func_num_args() === 0) {\n            $data = $this->_data;\n        }\n\n        if (is_array($data) || substr($data, 0, 4) != '%PDF') {\n            $html = $this->to_html($data);\n\n            \u002F\u002F Use your PDF lib of choice. For example mpdf\n            $mpdf = new \\Mpdf\\Mpdf();\n            $mpdf->WriteHTML($html);\n            return $mpdf->Output('', 'S');\n        }\n\n        return $data;\n    }\n}\n```\n","CodeIgniter RestServer 是一个为 CodeIgniter 3 设计的完全 RESTful 服务器实现，通过单一库、配置文件和控制器来简化开发过程。其核心功能包括支持多种 HTTP 方法（如 GET, POST, PUT, DELETE 等），并允许开发者轻松扩展支持的数据格式。该项目采用 PHP 编写，要求 PHP 版本至少为 7.2 和 CodeIgniter 3.1.11+。它非常适合需要快速搭建 REST API 接口的场景，特别是对于那些已经在使用 CodeIgniter 框架或希望基于此框架构建后端服务的应用程序来说，是一个非常实用的选择。安装简便，可通过 Composer 进行管理，易于集成到现有项目中。",2,"2026-06-11 03:17:33","top_language"]