{"id":27915184,"url":"https://github.com/sprintcube/cakephp-rest","last_synced_at":"2026-02-26T10:36:13.509Z","repository":{"id":57043095,"uuid":"128907964","full_name":"sprintcube/cakephp-rest","owner":"sprintcube","description":"CakePHP REST Plugin - Easily build REST API endpoints in your CakePHP application.","archived":false,"fork":false,"pushed_at":"2020-07-26T21:14:22.000Z","size":41,"stargazers_count":25,"open_issues_count":7,"forks_count":6,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-12-17T14:36:12.779Z","etag":null,"topics":["api","cakephp","cakephp-plugin","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/sprintcube.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}},"created_at":"2018-04-10T09:28:47.000Z","updated_at":"2023-08-06T21:24:05.000Z","dependencies_parsed_at":"2022-08-24T01:21:05.771Z","dependency_job_id":null,"html_url":"https://github.com/sprintcube/cakephp-rest","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/sprintcube/cakephp-rest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sprintcube%2Fcakephp-rest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sprintcube%2Fcakephp-rest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sprintcube%2Fcakephp-rest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sprintcube%2Fcakephp-rest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sprintcube","download_url":"https://codeload.github.com/sprintcube/cakephp-rest/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sprintcube%2Fcakephp-rest/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29856738,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-26T08:51:08.701Z","status":"ssl_error","status_checked_at":"2026-02-26T08:50:19.607Z","response_time":89,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","cakephp","cakephp-plugin","rest","rest-api"],"created_at":"2025-05-06T15:35:57.376Z","updated_at":"2026-02-26T10:36:13.491Z","avatar_url":"https://github.com/sprintcube.png","language":"PHP","readme":"# Rest Plugin for CakePHP\n\n[![Build Status](https://travis-ci.org/sprintcube/cakephp-rest.svg?branch=master)](https://travis-ci.org/sprintcube/cakephp-rest)\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/sprintcube/cakephp-rest/master/LICENSE)\n[![Total Downloads](https://poser.pugx.org/sprintcube/cakephp-rest/downloads)](https://packagist.org/packages/sprintcube/cakephp-rest)\n[![Latest Stable Version](https://poser.pugx.org/sprintcube/cakephp-rest/v/stable)](https://packagist.org/packages/sprintcube/cakephp-rest)\n\nThis plugin simplifies the REST API development for your CakePHP 3 application. It simply converts the output of your controller into a JSON response.\n\n## Installation\n\nYou can install this plugin into your CakePHP application using [composer](http://getcomposer.org).\n\nThe recommended way to install composer packages is:\n\n```\ncomposer require sprintcube/cakephp-rest\n```\n\nAfter installation, [Load the plugin](http://book.cakephp.org/3.0/en/plugins.html#loading-a-plugin)\n\n```php\nPlugin::load('Rest', ['bootstrap' =\u003e true]);\n```\n\nOr, you can load the plugin using the shell command\n\n```sh\n$ bin/cake plugin load -b Rest\n```\n\n## Usage\n\nNo major change requrires in the way you code in your CakePHP application. Simply, just add one parameter to your route configuration `isRest` like,\n\n```php\n$routes-\u003econnect('/foo/bar', ['controller' =\u003e 'Foo', 'action' =\u003e 'bar', 'isRest' =\u003e true]);\n```\n\nAnd extend your controller to `RestController` and everything will be handled by the plugin itself. For example,\n\n```php\n\u003c?php\n\nnamespace App\\Controller;\n\nuse Rest\\Controller\\RestController;\n\n/**\n * Foo Controller\n *\n */\nclass FooController extends RestController\n{\n\n    /**\n     * bar method\n     *\n     * @return Response|void\n     */\n    public function bar()\n    {\n        $bar = [\n            'falanu' =\u003e [\n                'dhikanu',\n                'tamburo'\n            ]\n        ];\n\n        $this-\u003eset(compact('bar'));\n    }\n}\n\n```\n\nAnd that's it. You will see the response as below.\n\n```json\n{\n    \"status\": \"OK\",\n    \"result\": {\n        \"bar\": {\n            \"falanu\": [\n                \"dhikanu\",\n                \"tamburo\"\n            ]\n        }\n    }\n}\n```\n\nDoesn't it too simple? Whatever `viewVars` you set from your controller's action using `set()` method, will be converted into JSON response.\n\n### Response Format\nThis plugin returns the response in the following format.\n\n```json\n{\n    \"status\": \"OK\",\n    \"result\": {\n        ...\n    }\n}\n```\nThe `status` key may contain OK or NOK based on your response code. For all successful responses, the code will be 200 and the value of this key will be OK. \n\nIn case of error or exception, the value of `status` will become NOK. Also, based on your application's `debug` setting, it will contain the exception and trace data.\n\nThe `result` key contains the actual response. It holds all the variables set from your controller. This key will not be available in case of error/exception.\n\n## Require Authentication??\nThis plugin also provides an option to authenticate request using JWT. Simply, just add one more parameter to your route configuration `requireAuthorization` like,\n\n```php\n$routes-\u003econnect('/foo/bar', ['controller' =\u003e 'Foo', 'action' =\u003e 'bar', 'isRest' =\u003e true, 'requireAuthorization' =\u003e true]);\n```\n\nNow, the plugin will check for the JWT token in the request in form of a header, query parameter or post data. If you want to pass the token in the header, use the following format.\n\n```\nAuthorization: Bearer [token]\n```\n\nAnd for query parameter or post data, use `token` parameter and set the token as a value of the parameter.\n\n### Generate a token\nIf you require the authentication in API, you first must grant the token to the user who is making the API request. In general, when a user logs in, the response should contain the token for all next requests.\n\nTo generate a token, use the method from Utility class of the plugin: `JwtToken::generate()`.\n\n```php\n/**\n * login method\n *\n * @return Response|void\n */\npublic function login()\n{\n    // you user authentication code will go here, you can compare the user with the database or whatever\n    \n    $payload = [\n        'id' =\u003e \"Your User's ID\",\n        'other' =\u003e \"Some other data\"\n    ];\n\n    $token = \\Rest\\Utility\\JwtToken::generate($payload);\n\n    $this-\u003eset(compact('token'));\n}\n```\n\nAnd it will return the token in response. So, in next API calls, a user can use that token for authorization. You can add whatever data is required in your payload.\n\nBy default, the plugin uses the predefined key and algorithm to generate JWT token. You can update this configuration by creating `config/rest.php` file. The content of this configuration file will be as following,\n\n```php\n\u003c?php\nreturn [\n    'Rest' =\u003e [\n        'jwt' =\u003e [\n            'key' =\u003e 'PUT YOUR KEY HERE', // it should contain alphanumeric string with symbols\n            'algorithm' =\u003e 'HS256' // See https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40\n        ]\n    ]\n];\n```\n\n### Access token data\nIf there is a valid token available in the request, you can access it in your controller using the `token` and `payload` properties.\n\n```php\n/**\n * view method\n *\n * @return Response|void\n */\npublic function view()\n{\n    $token = $this-\u003etoken;\n\n    $payload = $this-\u003epayload;\n\n    // your action logic...\n}\n```\nThese properties are also available in your controller's `beforeFilter` method, so you can put additional authentication logic there.\n\n## Reporting Issues\nIf you have a problem with this plugin or found any bug, please open an issue on [GitHub](https://github.com/sprintcube/cakephp-rest/issues).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsprintcube%2Fcakephp-rest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsprintcube%2Fcakephp-rest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsprintcube%2Fcakephp-rest/lists"}