CakeDC / cakephp-api

API Plugin for CakePHP
Other
61 stars 33 forks source link

API Route on my own service dosn't work #76

Closed jreiher closed 3 years ago

jreiher commented 3 years ago

I try this form our documentation (service.md)

use App\\Posts\\FlagAction;

    public function initialize()
    {
        parent::initialize(); 
        $this->mapAction('flag', FlagAction::class, [
            'method' => ['POST'],
            'mapCors' => true,
            'path' => ':id/:flag'
        ]); 
    }

message: A route matching "/flag/1/myflag" could not be found. on line 199 in .../vendor/cakephp/cakephp/src/Routing/RouteCollection.php

I take a look into method "mapAction" if $route['path'] is set then the actionName will be missing.

Here my work arround:

use App\\Posts\\FlagAction;

    public function initialize()
    {
        parent::initialize(); 
        $this->mapAction('flag', FlagAction::class, [
            'method' => ['POST'],
            'mapCors' => true,
            'path' => 'flag/:id/:flag'
        ]); 
    }

Is it wanted like that?

skie commented 3 years ago

Take a look into https://github.com/gothinkster/cakephp-realworld-example-app/blob/master/src/Service/ProfilesService.php I suppose you need to define correct regex for id and for flag

skie commented 3 years ago

One more note. Dont forget that your real url should be prefixed with service name too

skie commented 3 years ago

Do you have more questions?

jreiher commented 3 years ago

Not at this moment. Sorry, the time passed very quickly, we a new project. Thanks for the tip on the real world example. I have found everthing what i need.

Thank You