Basic PSR-7 request router
<?php
$r = new Ruta\Router;
$r->get('/test/:id', fn() => 'test');
$r->post('/test/:id', fn() => 'test');
$r->delete('/test/:id', fn() => 'test');
$match = $r->dispatch(new ServerRequest('GET', '/test/1'));
// The mapped callable/class to handle the route
$handler = $match->getHandler();
// If a dynamic route those values are stored here
$attrs = $match->getAttributes(); This router comes with a pre-configured PSR compliant middlware for doing routing
<?php
/** @var Psr\Http\Message\ResponseFactoryInterface $responseFactory */
$responseFactory = somePsrResponseFactory();
$middleware = new Ruta\RouteMiddleware($r, $responseFactory);A re-runnable benchmark comparing ruta against FastRoute and Symfony's
compiled router lives in benchmark/. Run it locally
with cd benchmark && composer install && php run.php, or trigger the
Benchmark GitHub Actions workflow for results in the job summary.