No Code Attached Yet
avatar rubenferreira97
rubenferreira97
11 Jun 2024

Steps to reproduce the issue

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.

Expected result

Content-Type: application/json; charset=utf-8

Actual result

Content-Type: text/plain; charset=utf-8

System information (as much as possible)

Joomla 4.4.5

avatar rubenferreira97 rubenferreira97 - open - 11 Jun 2024
avatar joomla-cms-bot joomla-cms-bot - change - 11 Jun 2024
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 11 Jun 2024
avatar Quy Quy - close - 23 Jun 2024
avatar Quy Quy - change - 23 Jun 2024
Status New Closed
Closed_Date 0000-00-00 00:00:00 2024-06-23 16:09:06
Closed_By Quy
avatar Quy
Quy - comment - 23 Jun 2024

Closing as having a pull request #43689.

Add a Comment

Login with GitHub to post a comment