Home > Software engineering >  CakePHP 4 - How do I create a simple proof of concept REST API?
CakePHP 4 - How do I create a simple proof of concept REST API?

Time:03-05

How do I get a simple proof-of-concept REST API working in CakePHP 4?

I have followed the guides in CakePHP's cookbook Missing Controller Error

CodePudding user response:

Due to the cakephp naming convention, you have that error message.

Solution I:

use url like: http://localhost/app/locate-i-t-a-p-i.json

Solution II: Add in router:

//http://localhost/app/locateitapi.json
$builder->connect('/locateitapi', ['controller' => 'LocateITAPIController', 'action' => 'index']);
$builder->connect('/locateitapi/add', ['controller' => 'LocateITAPIController', 'action' => 'add']);

Solution III:

rename your controller class like:

class LocateItApiController ...
// http://localhost/app/locate-it-api.json

class LocateitapiController ...
// http://localhost/app/locateitapi.json
  • Related