{"id":13560313,"url":"https://github.com/chriskacerguis/codeigniter-restserver","last_synced_at":"2025-08-19T02:34:05.628Z","repository":{"id":595512,"uuid":"230589","full_name":"chriskacerguis/codeigniter-restserver","owner":"chriskacerguis","description":"A fully RESTful server implementation for CodeIgniter using one library, one config file and one controller.","archived":false,"fork":false,"pushed_at":"2024-11-22T13:16:08.000Z","size":3997,"stargazers_count":4890,"open_issues_count":4,"forks_count":2845,"subscribers_count":403,"default_branch":"master","last_synced_at":"2025-05-08T09:42:14.387Z","etag":null,"topics":[],"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/chriskacerguis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2009-06-18T15:54:54.000Z","updated_at":"2025-05-08T01:40:01.000Z","dependencies_parsed_at":"2023-07-06T14:16:55.878Z","dependency_job_id":"6f6793f3-a339-4c6c-9128-aa9e69c201db","html_url":"https://github.com/chriskacerguis/codeigniter-restserver","commit_stats":{"total_commits":701,"total_committers":180,"mean_commits":"3.8944444444444444","dds":0.6847360912981455,"last_synced_commit":"2e1cbd347625cb489776528696f7980984e9b7f5"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chriskacerguis%2Fcodeigniter-restserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chriskacerguis%2Fcodeigniter-restserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chriskacerguis%2Fcodeigniter-restserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chriskacerguis%2Fcodeigniter-restserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chriskacerguis","download_url":"https://codeload.github.com/chriskacerguis/codeigniter-restserver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253169411,"owners_count":21865040,"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":[],"created_at":"2024-08-01T13:00:41.690Z","updated_at":"2025-05-09T00:28:08.538Z","avatar_url":"https://github.com/chriskacerguis.png","language":"PHP","readme":"# CodeIgniter RestServer\n\n[![StyleCI](https://github.styleci.io/repos/230589/shield?branch=master)](https://github.styleci.io/repos/230589)\n\nA fully RESTful server implementation for CodeIgniter using one library, one config file and one controller.\n\n## Important!!\n\nCodeIgniter 4 includes REST support out of the box and therefore does not require the RestServer.\n\nSee the documentation here: [RESTful Resource Handling](https://codeigniter4.github.io/userguide/incoming/restful.html)\n\n## Requirements\n\n- PHP 7.2 or greater\n- CodeIgniter 3.1.11+\n\n## Installation\n\n```sh\ncomposer require chriskacerguis/codeigniter-restserver\n```\n\n## Usage\n\nCodeIgniter Rest Server is available on [Packagist](https://packagist.org/packages/chriskacerguis/codeigniter-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/codeigniter-restserver\": \"^3.1\"\n```\n\nor run\n\n```sh\ncomposer require chriskacerguis/codeigniter-restserver\n```\n\nNote that you will need to copy `rest.php` to your `config` directory (e.g. `application/config`)\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://domain/api/users/` will return the list of all users\n* `http://domain/api/users/id/1` 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        // Construct the parent class\n        parent::__construct();\n    }\n\n    public function users_get()\n    {\n        // Users from a data store e.g. database\n        $users = [\n            ['id' =\u003e 0, 'name' =\u003e 'John', 'email' =\u003e 'john@example.com'],\n            ['id' =\u003e 1, 'name' =\u003e 'Jim', 'email' =\u003e 'jim@example.com'],\n        ];\n\n        $id = $this-\u003eget( 'id' );\n\n        if ( $id === null )\n        {\n            // Check if the users data store contains users\n            if ( $users )\n            {\n                // Set the response and exit\n                $this-\u003eresponse( $users, 200 );\n            }\n            else\n            {\n                // Set the response and exit\n                $this-\u003eresponse( [\n                    'status' =\u003e false,\n                    'message' =\u003e 'No users were found'\n                ], 404 );\n            }\n        }\n        else\n        {\n            if ( array_key_exists( $id, $users ) )\n            {\n                $this-\u003eresponse( $users[$id], 200 );\n            }\n            else\n            {\n                $this-\u003eresponse( [\n                    'status' =\u003e false,\n                    'message' =\u003e '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/MY_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        // This can be the library's chriskacerguis\\RestServer\\Format\n        // or your own custom overloaded Format class (see bellow)\n        $this-\u003eformat = new Format();\n    }\n}\n```\n\n2. Extend the `Format` class (can be created as a CodeIgniter library in `libraries/Format.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 \u0026\u0026 func_num_args() === 0) {\n            $data = $this-\u003e_data;\n        }\n\n        if (is_array($data) || substr($data, 0, 4) != '%PDF') {\n            $html = $this-\u003eto_html($data);\n\n            // Use your PDF lib of choice. For example mpdf\n            $mpdf = new \\Mpdf\\Mpdf();\n            $mpdf-\u003eWriteHTML($html);\n            return $mpdf-\u003eOutput('', 'S');\n        }\n\n        return $data;\n    }\n}\n```\n","funding_links":[],"categories":["Web Services","PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchriskacerguis%2Fcodeigniter-restserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchriskacerguis%2Fcodeigniter-restserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchriskacerguis%2Fcodeigniter-restserver/lists"}