composer require sprintcube/cakephp-rest code example
Example: composer require sprintcube/cakephp-rest
composer require sprintcube/cakephp-rest
bin/cake plugin load -b Rest
$routes->connect('/foo/bar', ['controller' => 'Foo', 'action' => 'bar', 'isRest' => true]);
namespace App\Controller\Api;
use Rest\Controller\RestController;
class ProductsController extends RestController
public function beforeFilter(Event $event)
{
parent::beforeFilter($event);
$this->response->cors($this->request)
->allowOrigin('*')
->allowMethods(['GET', 'PUT', 'POST', 'OPTIONS'])
->allowHeaders(['X-CSRF-Token'])
->allowCredentials()
->maxAge(300)
->build();
}