Comments (42)
Feels like the plugin is designed to give people problems doing something so simple. It is really terrible piece of code.
from cakephp-api.
@tgoeminne this plugin has some defaults and conventions that may not match what you usually do or expect in your project. I've used it many times, and it provides what I usually need when dealing with an API project. I understand you could be frustrated because it does not work as you expect though.
What contributions could you do to improve the docs or the code so other users could benefit from them?
I see @skie is already taking some time to help you... maybe this could become an input for the documentation later for other users trying to do the same you're doing here?
Thanks,
from cakephp-api.
Api plugin is 100% RESTful. So routes based on REST verbs and urls based on REST convetions. So correct there would be GET, /articles for index, and GET,/articles/:id for view, POST,/articles for add, and PUT,/articles/:id for edit, and finally DELETE,/aritcles/:id for delete.
from cakephp-api.
`<?php
namespace App\Service\v1;
use CakeDC\Api\Service\Service as Service;
class ArticlesService extends Service {
protected $_actionsClassMap = [
'describe' => '\CakeDC\Api\Service\Action\CrudDescribeAction',
'index' => '\App\Service\v1\Action\Articles\IndexAction',
'view' => '\App\Service\v1\Action\Articles\ViewAction',
'add' => '\App\Service\v1\Action\Articles\AddAction',
'edit' => '\App\Service\v1\Action\Articles\EditAction',
'delete' => '\App\Service\v1\Action\Articles\DeleteAction',
];
}`
Then
`<?php
namespace App\Service\v1\Action\Articles;
use CakeDC\Api\Service\Action\CrudIndexAction;
class IndexAction extends CrudIndexAction {
public function execute()
{
$results = $this->_getEntities();
return $results;
}
}`
{"status":"error","message":"A route matching "/articles" could not be found.","code":404,"data":null}
from cakephp-api.
Is versions enabled in config/api.php?
from cakephp-api.
yes
from cakephp-api.
'useVersioning' => true,
'versionPrefix' => 'v',
from cakephp-api.
When I use FallbackService instead of service I can access /api/v1/articles and then it works, but then also the actions view,... does not work (missing routes). When I use Service, I can not even access /api/v1/articles (missing route). In my other post I also mention the config, I have to put vv1 in the config files so that the version config is loaded when request v1 on fallbackservice...
from cakephp-api.
i would create class ArticlesService extends FallbackService
and overload only needed actions. Also I recommend to take look on https://github.com/gothinkster/cakephp-realworld-example-app
from cakephp-api.
I just use actionsClassMap and then use execute method in the action. Is that not enough to get it to work?
from cakephp-api.
Everything just show missing routes when I use api/articles/view/1, if I use versioning or not, this plugin another type of give me a serious headache to try it to get to work.... also the documentation seriously lacking as usual. Did you see the link to routes is pointing to 404?
from cakephp-api.
you used Service not CrudService or FallbackService
from cakephp-api.
with fallbackservice is the same, it doesn't work.
from cakephp-api.
I am looking at it now. I thought it would be more easy to have the request go to /api/articles/view/18 then to api/articles/18
Need to look into it more, but is pretty confusing. Is there somewhere code or like an sdk that an end user would use on third party php website to access the api?
from cakephp-api.
$actions = [
'index' => $reverseRouter->link('self', $path, 'GET'),
'add' => $reverseRouter->link('add', $path, 'POST'),
'edit' => $reverseRouter->link('edit', $path . '/{id}', 'PUT'),
'delete' => $reverseRouter->link('delete', $path . '/{id}', 'DELETE'),
];
from cakephp-api.
I also see that you can use cakdc users to authorize, but I can not find any documentation on how to do this. Both for sending the request and setting it up.
I am sending post request and I get csrf token missing...
There is a link to jwt tutorial which also goes to a 404 page...
from cakephp-api.
I also see that you can use cakdc users to authorize, but I can not find any documentation on how to do this. Both for sending the request and setting it up.
I am sending post request and I get csrf token missing...
There is a link to jwt tutorial which also goes to a 404 page...
Sorry, meaby the link is broken on the main documentation.
https://github.com/CakeDC/cakephp-api/blob/master/docs/Documentation/Auth/jwt.md
from cakephp-api.
Is there somewhere a tutorial how to do the api request with auth via cakedc users? And also so it works with csrf and such...?
from cakephp-api.
Hello @tgoeminne, I don't know if this repo can Help you. I did it last year.
https://github.com/delamux/apiplug
from cakephp-api.
https://www.cakedc.com/yevgeny_tomenko/2020/06/29/cakedc-api-plugin-authentication-and-authorization
from cakephp-api.
I am using basic token authorization for now. where you add ?token=xxxxx to the back
I am running in the problem with request POST being blackholed due to missing csrf token. How can you disable csrf token in service/action?
from cakephp-api.
Then disable the csrf middleware by changing routes and application.php. Now the POST request being blackholed.
from cakephp-api.
is SecurityComponent enabled for these actions?
The way to disable Csrf is creating a specific routing scope "without" loading the csrf middleware into it.
from cakephp-api.
Yes I disabled csrf, now looking how I can dissable security component for specific action. I thought the point of mapCors was that it is allowed by default from another domain, but it seems it isn't working like that.
I try put this in Articleservice but not work
`
public function beforeFilter(Event $event)
{
parent::beforeFilter($event);
$this->Security->setConfig('unlockedActions', ['add']);
}
`
from cakephp-api.
That should not be an issue if you plug Api using the https://github.com/CakeDC/cakephp-api/blob/master/src/Middleware/ApiMiddleware.php
from cakephp-api.
How do I do that?
from cakephp-api.
https://github.com/gothinkster/cakephp-realworld-example-app/blob/master/src/Application.php#L102
Example there ^
from cakephp-api.
Where do I insert that then? There is nowhere any information about this in the docs or configuration/installation... Why is this so complicated to get it to work properly?
from cakephp-api.
We need to properly document the Api middleware load, you're right.
I understand the specific problem is Security component interacting with your ApiController, so I would suggest either:
- Setup ApiMiddleware to ignore the controller layer and bypass Security
- Properly configure Security, for example in your AppController, check if the request belongs to the Api and disable SecurityComponent.
from cakephp-api.
if(!$this->getRequest()->getAttributes()['params']['controller'] == 'Api'){ $this->loadComponent('Security'); }
from cakephp-api.
Now when I post I receive another error:
{"error":{"code":422,"message":"Validation failed","validation":{"version":{"_required":"This field is required"}}}}
from cakephp-api.
I have set useVersioning to false, then why is this field required?
from cakephp-api.
I don't understand why Api is considered a "controller", when it should really just be a "prefix"...
from cakephp-api.
Ok I got it to work now after disabling both csrf and security for api controller.
from cakephp-api.
I would have probably been better of just making a prefix api and then send response with json....
from cakephp-api.
I have a question about the post data adding of files. What is the best way to send files to api? I am using cakephp upload...
from cakephp-api.
Hi, posting a file is the same as posting any other data, the tmp file will be available in the request and using upload or any other plugin to manage the posted data will process the file and move it somewhere else in your backend. Are you facing any specific issue while dealing the the uploaded files?
Thanks,
from cakephp-api.
Still need to test it..
from cakephp-api.
Hi,
I am sending postwithmultipartformdata to api and then when I do print_r on $this->getData() to debug log. I can see
[--------------------------d1f95fef5s642baf
Content-Disposition:_attachment;_name] => "test.json"; filename="test.json"
Content-Type: application/octet-stream
and then json contents.
If I understand correctly in this case $this->getData() is a file? Then how do I get the actual json data in an array?
from cakephp-api.
Possible you want to define custom RequestParser inherited from Api\Service\RequestParser\BaseParser or just want access to request object with $this->getService()->getRequest()
from cakephp-api.
I do getData but I see content disposition inthere which is normally a header?
from cakephp-api.
closed as obsolete support issue
from cakephp-api.
Related Issues (20)
- 8.0 branch crud not working - Forbidden authorization request HOT 4
- versioning config HOT 1
- 8.0 versioning does not work HOT 5
- Jwt authentication is not working in 8.0.0 HOT 1
- JSendRenderer _error() function won't accept string as error code
- Can't install version >8.0.0 due to dependency on lcobucci/jwt:3.3.x-dev (suggestion: depend on stable version, latest is lcobucci/jwt:4.0.0) HOT 1
- All errors are returned with [status code 200 OK] in the response header. It should return the real status code of the exception. HOT 2
- CrudAction::_getEntities() should return a ResultSetInterface instead of a ResultSet - errors might happen if not.
- No way to disable SortExtension to prevent it of executing on some requests HOT 1
- loading a component inside action HOT 1
- JWT tokens not authorizing until a minute after refresh HOT 2
- API Route on my own service dosn't work HOT 4
- Cake 4 release HOT 1
- Missing \ Wrong documentation on routing HOT 2
- Disabling public access HOT 2
- Feature request: Improve Action::getData()
- Espose api for plugins HOT 1
- Dependency Injection inside service actions
- Unable to call method validateUnique in table provider for field username HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cakephp-api.