PHP API Router
Supports:
- GET
- PUT
- POST
- DELETE
- PATCH
for custom values, use all.
Make sure include path is set to the location where you put the script.
include('Router.php');
Router::get('/endpoint',function() {
// todo
});
Router::all('/endpoint',function() {
// todo
});
All code in the 'set' route executes before any other routes. This is a good place for CORS policys and/or authorization
Router::set('/',function() {
// todo
});
$routes = Router::getInstance()->routes;
To process routes and run their functions, use a foreach loop, make sure you are accessing the singleton for the Router class or this will not work.
foreach(Router::getInstance()->routes as $key => $value) {
echo $value['name'];
}