PHPackages                             aniruddh/phprouter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. aniruddh/phprouter

ActiveLibrary[HTTP &amp; Networking](/categories/http)

aniruddh/phprouter
==================

A simple, lightweight, and fast PHP router with supported middleware and trailing slash or non-trailing slash mode.

v1.0.0(3y ago)171MITPHPPHP &gt;=7.4.0

Since Sep 25Pushed 2y ago1 watchersCompare

[ Source](https://github.com/aniruddhnishad/phprouter)[ Packagist](https://packagist.org/packages/aniruddh/phprouter)[ Docs](https://github.com/aniruddhnishad/phprouter)[ RSS](/packages/aniruddh-phprouter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (3)Used By (0)

PHPRoute - simple, lightweight, and fast router
===============================================

[](#phproute---simple-lightweight-and-fast-router)

Install
-------

[](#install)

To install with composer:

```
composer require aniruddh/phprouter
```

Requires PHP 7.4 or newer.

Usage
-----

[](#usage)

Here's a basic usage example:

```
require_once('path/to/vendor/autoload.php');
use Aniruddh\Router\Router;
$router = new Router();
// default method is GET does not required to specify
$router->add('/', function() {
    echo 'get Home page';
});

$router->add('/test', function() {
    echo 'get test1';
});

$router->add('/test', function() {
    echo 'post test';
});

//you can specify if you want
$router->add('/test1', function() {
    echo 'get test1';

}, ['GET']);

//Except GET you have to specify the method
$router->add('/test1', function() {
    echo 'post test1';
}, ['POST']);

//you can specify multiple method
$router->add('/test2', function() {
    echo 'get and post test2';
}, ['GET', 'POST']);

//set 404 if not default 404 page shown
$router->set404(function(){
    echo "404 not found!  url: " . htmlentities($_SERVER['REQUEST_URI']);
});
//run the router
$router->run();
```

### Defining routes

[](#defining-routes)

```
//method and middleware must be an array
$route->add($route, $callback, $method, $middleware);
```

```
//router use regex for route matching
// Matches /users/42, but not /users/abc
$router->add('/users/\d+', 'callback');
```

```
// Example with middleware
$route->add('/users/\d+', 'callback', ['GET'], ['before'=> callabck, 'after'=> callback]);
```

```
//Example with class object and method
$router->('/users', ['classname','method']);
```

```
//Example with trailing slash option enable
require_once('path/to/vendor/autoload.php');

use Aniruddh\Router\Router;

$router = new Router(true, 1); //default is false and 0 // 0 means without trailing slash
// default method is GET does not required to specify
$router->add('/', function() {
    echo 'get Home page';
});
$router->('/users', callback); //use can specify route like $router->('users', callback); both version will work
```

Note
----

[](#note)

coming soon...

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1325d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ac4a79a5a45b422e92f0cdcba5807ec07235e02abba592e44fc6800f8d15f803?d=identicon)[aniruddh](/maintainers/aniruddh)

---

Top Contributors

[![aniruddhnishad](https://avatars.githubusercontent.com/u/31369406?v=4)](https://github.com/aniruddhnishad "aniruddhnishad (13 commits)")

---

Tags

routerroutingsimple-php-routerphp-routerphprouterphp-routingPHP Routephproutephproutingfast php router

### Embed Badge

![Health badge](/badges/aniruddh-phprouter/health.svg)

```
[![Health](https://phpackages.com/badges/aniruddh-phprouter/health.svg)](https://phpackages.com/packages/aniruddh-phprouter)
```

###  Alternatives

[symfony/routing

Maps an HTTP request to a set of configuration variables

7.6k789.4M1.8k](/packages/symfony-routing)[nikic/fast-route

Fast request router for PHP

5.3k92.4M668](/packages/nikic-fast-route)[altorouter/altorouter

A lightning fast router for PHP

1.3k3.4M68](/packages/altorouter-altorouter)[aura/router

Powerful, flexible web routing for PSR-7 requests.

5231.5M67](/packages/aura-router)[aplus/routing

Aplus Framework Routing Library

2491.6M3](/packages/aplus-routing)[pmjones/auto-route

Automatically routes HTTP request to action classes.

20158.6k6](/packages/pmjones-auto-route)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
