Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean install #5

Open
robitmoh opened this issue Feb 3, 2023 · 2 comments
Open

Clean install #5

robitmoh opened this issue Feb 3, 2023 · 2 comments

Comments

@robitmoh
Copy link

robitmoh commented Feb 3, 2023

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 ...)

@cnizzardini
Copy link
Member

Is this a bug report?

@robitmoh
Copy link
Author

robitmoh commented Feb 5, 2023

Yes and not 😄
I found some broken and wrong link in the documentation this is bug? I think no.

I have result to my step by step trying, but i don't know this is correct, or not

My test api code is give it back json result but only when I call the url with .json extension.
Without extension I get" missing template page"

I think that's not good, I want call my api without extension to json result, but maybe that's how you planned it the plugin.


mod 02-16
ok must to send the request with Application/json header


I don't know this my settings error, or a bug

My thinks:
The datasource replace from mysql to sqlite in the app.php is not practical.
The router.php duplicate definition is a bug (I not write any to router.php only I generate the code)

Thanks your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants