It is fairly common to add json handler to a CakePHP route and have it automatically respond with formatted JSON. Consider this example. In your route: $routes->prefix(‘Api’, function (RouteBuilder $routes) { $routes->setExtensions([‘json’]); $routes->fallbacks(DashedRoute::class); }); In your controller: public function initialize(): void { parent::initialize(); $this->addViewClasses([\Cake\View\JsonView::class]); $this->viewBuilder()->setOption(‘serialize’, true); } So now when you request actions in that… Continue reading Custom file extensions (e.g. .env): routing and rendering serialized responses