J4 create only C of CRUD route

35 views
Skip to first unread message

GhiaMar

unread,
Jul 1, 2022, 8:51:50 AM7/1/22
to Joomla! General Development
Hi! in my development I created an webservice plugin with this code

public function onBeforeApiRoute(&$router)
{
     $router->createCRUDRoutes(
         'v1/XXXX/XXXX',
         'XXXX',
         ['component' => 'com_XXXX']
    );
}

¿Is it possible to disable all routes except the C (POST) route? because my API endpoint should only receive new data, I'm not interested in listing anything or update from outside the Joomla server.

Thanks!

MarkRS

unread,
Jul 1, 2022, 11:07:12 AM7/1/22
to Joomla! General Development
Have a look at that method, createCRUDRoutes, and you'll see how they're all created and then you can just do that with the one that you want.

GhiaMar

unread,
Jul 1, 2022, 3:48:14 PM7/1/22
to Joomla! General Development
Well, that's the issue, I just want to be able to CREATE (POST) and nothing else in that endpoint. Is that possible? I mean, if someone tries GET v1/XXXX/XXXX or GET v1/XXXX/XXXX/1 or PATCH v1/XXXX/XXXX/1 it should fail...

MarkRS

unread,
Jul 2, 2022, 6:21:44 AM7/2/22
to Joomla! General Development
Yes, that's what you'll find in the createCRUDRoutes method, individual calls to create individual routes. Then, in the place that you would call "createCRUDRoutes" just make the call for the specific route(s) you want.

GhiaMar

unread,
Jul 4, 2022, 1:15:21 PM7/4/22
to Joomla! General Development
Got it! in the onBeforeApiRoute I can call createCRUDRoutes or create an array of routes then addRoutes, got the code from menus, modules and plugins webservices.

Thanks a lot!
Reply all
Reply to author
Forward
0 new messages