Welcome Guest, Not a member yet? Register   Sign In
Need help understanding the docs on RESTFul?
#3

(08-25-2020, 01:22 AM)tgix Wrote: There are ways to group routes - https://codeigniter4.github.io/userguide/incoming/routing.html#grouping-routes

M
y own restful API back-end is getting bigger and bigger. Now about 10 controllers with 20+ models and entities.
To handle this route-wise, I am using groups like this so I don't have to configure the filter etc for each route entry.
PHP Code:
$routes->group('config', ['except' => ['new''edit'], 'filter' => 'bearer-auth:conf'], function ($routes) {

    $routes->get('(:segment)/(:segment)/changehistory''config\Changehistory::$1/$2');

    $routes->resource('credits', ['controller' => 'config\Credits']);

    // Routes for certifications
    $routes->options('certifications/(:segment)/logo''Options::index');
    $routes->post('certifications/(:segment)/logo''config\Certifications::postCertLogo/$1');
    $routes->post('certifications/(:segment)/icon''config\Certifications::postCertIcon/$1');
    $routes->delete('certifications/(:segment)/logo''config\Certifications::deleteCertLogo/$1');
    $routes->delete('certifications/(:segment)/icon''config\Certifications::deleteCertIcon/$1');

    $routes->get('certifications/(:segment)/exams''config\Certifications::getCertExams/$1');
    $routes->get('certifications/(:segment)/issuedcerts''config\Certifications::getIssuedCerts/$1');
    $routes->get('certifications/(:segment)/certverdownload/(:segment)''config\Certifications::getCertVerDownload/$1/$2');
    $routes->delete('certifications/(:segment)/certverdownload/(:segment)''config\Certifications::deleteCertVerDownload/$1/$2');
    $routes->post('certifications/(:segment)/certverdownload/(:segment)''config\Certifications::postCertVerDownload/$1/$2');

    $routes->get('certifications/(:segment)/certversions''config\Certifications::getCertVersions/$1');
    $routes->put('certifications/(:segment)/certversions/(:segment)''config\Certifications::updateCertVersion/$1/$2');
    $routes->delete('certifications/(:segment)/certversions/(:segment)''config\Certifications::deleteCertVersion/$1/$2');
    $routes->post('certifications/(:segment)/certversions''config\Certifications::createCertVersion/$1');

    $routes->resource('certifications', ['controller' => 'config\Certifications']);

}); 

Thanks. I'm sure this is cool, but I'm taking baby steps here at the moment. I'm only just getting my head around all these 'automated' features in vCI4 ... and the docs seem to assume a lot, so it's a bit of a steep hill to climb ... but I'll keep this in the back of my head when I get advanced enough to group routes in a more 'clever' way.
Reply


Messages In This Thread
RE: Need help understanding the docs on RESTFul? - by blaasvaer - 08-25-2020, 01:46 AM



Theme © iAndrew 2016 - Forum software by © MyBB