Router::get('/home', function() { homePage(); });
Router::get('/user/:id', function($id) { $user = getUserById($id); showUserProfile($user); });
Router::get('/api/users', function() { // Return a list of all users }); Router::post('/api/users', function() { // Create a new user }); Router::put('/api/users/:id', function($id) { // Update an existing user }); Router::delete('/api/users/:id', function($id) { // Delete a user });There are many PHP router libraries available, including FastRoute, Symfony Routing, and Aura.Router. The examples above are written using the FastRoute package, which is a popular lightweight option.