tyler / ruta
Basic PSR-7 request router
v0.2.0
2026-06-10 19:58 UTC
Requires
- php: ^8.5
- psr/http-factory: ^1.0
- psr/http-message: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- guzzlehttp/psr7: ^2.4
- pestphp/pest: ^4.0
- php-parallel-lint/php-parallel-lint: ^1.4
- phpmd/phpmd: ^2.15
- phpstan/phpstan: ^2.1
- squizlabs/php_codesniffer: ^3.13 || ^4.0
This package is auto-updated.
Last update: 2026-06-11 02:01:36 UTC
README
Basic PSR-7 request router
Usage
Basic
<?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();
In Middleware
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);
Benchmarks
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.