PHPackages                             vakata/router - 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. vakata/router

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

vakata/router
=============

A simple request router

3.1.3(9y ago)118712MITPHPPHP &gt;=5.4.0

Since Dec 7Pushed 9y ago2 watchersCompare

[ Source](https://github.com/vakata/router)[ Packagist](https://packagist.org/packages/vakata/router)[ Docs](https://github.com/vakata/router)[ RSS](/packages/vakata-router/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (3)Versions (16)Used By (2)

router
======

[](#router)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e4f94d9995c31f6e27b754da8ce9de49b6f96cbb6f30988b45d80643a81ec52b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f76616b6174612f726f757465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vakata/router)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/c18b6db984d021ac307d3efc9b467754de01657b704d425881b72d59efe602f5/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f76616b6174612f726f757465722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/vakata/router)[![Code Climate](https://camo.githubusercontent.com/f0d931cf941e9570ddb16a62129ba3dbe2b80235818aedefe6f439be4214e13b/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f6769746875622f76616b6174612f726f757465722e7376673f7374796c653d666c61742d737175617265)](https://codeclimate.com/github/vakata/router)[![Tests Coverage](https://camo.githubusercontent.com/062e77b77ef5ab13416066c65458e1a429d216e0129948747f1364232d309b8e/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f636f7665726167652f6769746875622f76616b6174612f726f757465722e7376673f7374796c653d666c61742d737175617265)](https://codeclimate.com/github/vakata/router)

A simple request router.

Install
-------

[](#install)

Via Composer

```
$ composer require vakata/router
```

Usage
-----

[](#usage)

```
// create an instance
$router = new \vakata\router\Router();
$router
    ->get('/', function () { echo 'homepage'; })
    ->get('/profile', function () { echo 'user profile'; })
    ->group('/books/', function ($router) { // specify a prefix
        $router
            ->get('read/{i:id}', function ($matches) {
                // this method uses a named placeholder
                // when visiting /books/read/10 matches will contain:
                var_dump($matches); // 0 => books, 1 => read, 2 => 10, id => 10
                // placeholders are wrapped in curly braces {...} and can be:
                //  - i - an integer
                //  - a - any letter (a-z)
                //  - h - any letter or integer
                //  - * - anything (up to the next slash (/))
                //  - ** - anything (to the end of the URL)

                // placeholders can be named too by using the syntax:
                // {placeholder:name}

                // placeholders can also be optional
                // {?optional}
            })
            // for advanced users - you can use any regex as a placeholder:
            ->get('{(delete|update):action}/{(\d+):id}', function ($matches) { })
            // you can also use any HTTP verb
            ->post('delete/{i:id}', function ($matches) { })
    })
    // you can also bind multiple HTTP verbs in one go
    ->add(['GET', 'HEAD'], '/path', function () { })
    // you can also use with() statements to execute some code if the begging of the URL is a match to the prefix
    ->with('user', function () { echo 1; })
        ->get('view', function () { /* 1 will be echoed */ })
        ->post('chat', function () { /* 1 will be echoed */ });

// there is no need to chain the method calls - this works too:
$router->post('123', function () { });
$router->post('456', function () { });

// you finally run the router
try {
    $router->run(
        parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH),
        $_SERVER['REQUEST_METHOD']
    );
} catch (\vakata\router\RouterNotFoundException $e) {
    // thrown if no matching route is found
}
```

Read more in the [API docs](docs/README.md)

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [vakata](https://github.com/vakata)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity66

Established project with proven stability

 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

Every ~23 days

Total

15

Last Release

3531d ago

Major Versions

1.0.4 → 2.0.02016-04-17

2.0.3 → 3.0.02016-07-15

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/146052?v=4)[Ivan Bozhanov](/maintainers/vakata)[@vakata](https://github.com/vakata)

---

Top Contributors

[![vakata](https://avatars.githubusercontent.com/u/146052?v=4)](https://github.com/vakata "vakata (24 commits)")

---

Tags

routervakata

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vakata-router/health.svg)

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

###  Alternatives

[symfony/routing

Maps an HTTP request to a set of configuration variables

7.6k819.6M2.3k](/packages/symfony-routing)[nikic/fast-route

Fast request router for PHP

5.3k95.8M741](/packages/nikic-fast-route)[altorouter/altorouter

A lightning fast router for PHP

1.3k3.4M73](/packages/altorouter-altorouter)[league/route

Fast routing and dispatch component including PSR-15 middleware, built on top of FastRoute.

6673.2M137](/packages/league-route)[aura/router

Powerful, flexible web routing for PSR-7 requests.

5001.5M69](/packages/aura-router)[coffeecode/router

A classic CoffeeCode Router is easy, fast and extremely uncomplicated. Create and manage your routes in minutes!

180114.0k5](/packages/coffeecode-router)

PHPackages © 2026

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