tyler/ruta

Basic PSR-7 request router

Maintainers

Package info

github.com/tylersriver/ruta

pkg:composer/tyler/ruta

Statistics

Installs: 29

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 4

v0.2.0 2026-06-10 19:58 UTC

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.