I want to try this API in my project.
Over the learning I found some error in doc.
My step by step process ๐
Make clean cakephp install composer create-project --prefer-dist cakephp/app:4.* ./
The next steps from the mixerapi.com
composer require mixerapi/mixerapi
bin/cake plugin load MixerApi
Dependecies error..
I try with:
composer require mixerapi/mixerapi --with-all-dependencies
bin/cake plugin load MixerApi
This ready install, I always use 'Y' option
bin/cake mixerapi install
MixerAPI Installation Complete!
The workflow:
I have usable mysql schema so I try bake model
Baking your initial scaffolding using [bake](https://book.cakephp.org/bake/2/en/index.html) in conjunction with the [MixerAPI/Bake](https://mixerapi.com/bake) theme.
The two links is not usable, the first go to cakephp2 the second is empty (404)
I navigate form the left menu Bake Controllers
I set in the app_local.php the default datasources (mysql)
Bake the model and .... "Your database does not have any tables" and put full html source to console
I try to set in the app_local
'Datasources' => [
'default' => [
**'className' => Connection::class,
'driver' => Mysql::class,**
but "Datasource class Connection could not be found. "
I must to change the app.php
back the original className and driver from sqlite to mysql
After this I can bake the models.
bake model Subscribers --theme MixerApi/Bake
Next bake the controllers
bin/cake bake controller Subscribers --theme MixerApi/Bake
The validations is is skip at this situation
The routes
Building your RESTful routes with or without MixerAPI/Rest.
The second link is empty (404)
I try the " RESTful Routes " from the left menu
bin/cake mixerapi:rest route create
This modify the routes.php
bin/cake mixerapi:rest route list
-------------------------------------------------------------------------------
| Finding routes...
-------------------------------------------------------------------------------
+--------------------+-------------------+------------+-------------+--------+--------+
| Route name | URI template | Method(s) | Controller | Action | Plugin |
+--------------------+-------------------+------------+-------------+--------+--------+
| sites:add | /sites | POST | Sites | add | |
| sites:delete | /sites/{id} | DELETE | Sites | delete | |
| sites:edit | /sites/{id} | PUT, PATCH | Sites | edit | |
| sites:index | /sites | GET | Sites | index | |
| sites:view | /sites/{id} | GET | Sites | view | |
| subscribers:add | /subscribers | POST | Subscribers | add | |
| subscribers:delete | /subscribers/{id} | DELETE | Subscribers | delete | |
| subscribers:edit | /subscribers/{id} | PUT, PATCH | Subscribers | edit | |
| subscribers:index | /subscribers | GET | Subscribers | index | |
| subscribers:view | /subscribers/{id} | GET | Subscribers | view | |
| welcome:info | /welcome/info | GET | Welcome | info | |
+--------------------+-------------------+------------+-------------+--------+--------+
At this point I check in browser http://127.0.0.1:8006/subscribers/1001
Missing Template
Cake\View\Exception\MissingTemplateException
http://127.0.0.1:8006/subscribers/1001.json
Ready come back the json
I want result without the json extension
I see the generated routes.php and I think is not correct is contain duplicated definition (I not change manual )
<?php
use Cake\Routing\Route\DashedRoute;
use Cake\Routing\RouteBuilder;
use MixerApi\Rest\Lib\AutoRouter;
$routes->setRouteClass(DashedRoute::class);
$routes->scope('/', function (RouteBuilder $builder) {
$builder->setExtensions(['json', 'xml']);
$builder->resources('Welcome', ['only' => ['info'], 'map' => ['info' => ['action' => 'info', 'method' => 'GET']]]);
(new AutoRouter($builder))->buildResources();
$builder->connect('/', ['plugin' => 'SwaggerBake', 'controller' => 'Swagger', 'action' => 'index']);
$builder->connect('/contexts/*', ['plugin' => 'MixerApi/JsonLdView', 'controller' => 'JsonLd', 'action' => 'contexts']);
$builder->connect('/vocab', ['plugin' => 'MixerApi/JsonLdView', 'controller' => 'JsonLd', 'action' => 'vocab']);
$builder->fallbacks();
$builder->resources('Sites');
$builder->resources('Subscribers');
}, function (RouteBuilder $builder) {
$builder->setExtensions(['json', 'xml']);
$builder->resources('Welcome', ['only' => ['info'], 'map' => ['info' => ['action' => 'info', 'method' => 'GET']]]);
(new AutoRouter($builder))->buildResources();
$builder->connect('/', ['plugin' => 'SwaggerBake', 'controller' => 'Swagger', 'action' => 'index']);
$builder->connect('/contexts/*', ['plugin' => 'MixerApi/JsonLdView', 'controller' => 'JsonLd', 'action' => 'contexts']);
$builder->connect('/vocab', ['plugin' => 'MixerApi/JsonLdView', 'controller' => 'JsonLd', 'action' => 'vocab']);
$builder->fallbacks();
$builder->resources('Sites');
$builder->resources('Subscribers');
});
Finale in production I need to use the mixerapi only with prefix (ApiV1, Apiv2 ...)