CodeIgniter Forums
Routes no other than GET return main page - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Routes no other than GET return main page (/showthread.php?tid=82768)



Routes no other than GET return main page - PopeW - 08-20-2022

Hello there, I have this peculiar problem - I tinker around making CRUD REST API and I have defined these routes
PHP Code:
$routes->group('api/v1', ['namespace' => 'Api\V1''filter' => 'ApiGuard'],
    static function ($routes) {
        $routes->get('companies/(:num).json''\App\Controllers\Api\V1\Companies::company/$1');
        $routes->get('companies.json''\App\Controllers\Api\V1\Companies::fetchAll');
        $routes->post('companies/(:num).json''Companies::post');
        $routes->put('companies/(:num).json''Companies::put');
        $routes->delete('companies/(:num).json''Companies::delete');
    }
); 
In any case apart from GET method I get 303 redirect to main page, whereas via Guzzle I get 404 Not Found error. What have I done wrong here?
Thank you for your help.


RE: Routes no other than GET return main page - iRedds - 08-28-2022

If you use the "namespace" option, then you need to specify the full namespace.
['namespace' => '\App\Controllers\Api\V1'