class WebServices extends CMSPlugin implements SubscriberInterface {
public static function getSubscribedEvents(): array {
return [
'onBeforeApiRoute' => 'onBeforeApiRoute',
];
}
public function onBeforeApiRoute(Event $event) : void {
[$router] = array_values($event->getArguments());
$defaults = [
'component' => 'com_example',
'public' => true,
'format' => ['application/json'] // Does not work on Joomla 4 (works on Joomla 5)
];
$routes = [
new Route(['GET'], 'v1/example/configuration', 'configuration.get', [], $defaults),
];
$router->addRoutes($routes);
}
}
Inspect localhost/api/index.php/v1/example/configuration
request headers.
Content-Type: application/json; charset=utf-8
Content-Type: text/plain; charset=utf-8
Joomla 4.4.5
Labels |
Added:
No Code Attached Yet
|
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2024-06-23 16:09:06 |
Closed_By | ⇒ | Quy |
Closing as having a pull request #43689.