// Define routes $router = new Router(); $router->addRoute('GET', '/products', 'ProductController@index'); // Handle the request $request = Request::createFromGlobals(); $response = $router->handle($request); // Output the response $response->send();
// Define routes $router = new Router(); $router->addRoute('GET', '/products/:id', 'ProductController@show'); // Handle the request $request = Request::createFromGlobals(); $response = $router->handle($request); // Output the response $response->send();
// Define routes $router = new Router(); $router->addGroup('/api', function ($router) { $router->addRoute('GET', '/products', 'ApiController@index'); $router->addRoute('GET', '/products/:id', 'ApiController@show'); }); // Handle the request $request = Request::createFromGlobals(); $response = $router->handle($request); // Output the response $response->send();In this example, we defined a group of routes under the `/api` URL. The `ApiController` class is used for handling these routes. The `index` and `show` methods are called for the `/api/products` and `/api/products/{id}` URLs, respectively. PHP app router is a third-party library package in PHP. There are several PHP app router packages available, including FastRoute, Aura.Router, and Symfony Routing.