PHPackages                             alpha-zeta/simple-route - 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. [Framework](/categories/framework)
4. /
5. alpha-zeta/simple-route

ActiveLibrary[Framework](/categories/framework)

alpha-zeta/simple-route
=======================

Simple, fast, modern and flexible routing library

1.0.8(2mo ago)0401MITPHPPHP ^8.2

Since Jan 11Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/JackRabbit911/simple-route)[ Packagist](https://packagist.org/packages/alpha-zeta/simple-route)[ RSS](/packages/alpha-zeta-simple-route/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (8)Versions (11)Used By (1)

Simple route for PHP
====================

[](#simple-route-for-php)

simple, fast, modern, flexible PHP routing. PSR-7, PSR-15 compatible.

Installation
------------

[](#installation)

This package requires PHP version 8.2 or later.

```
composer require alpha-zeta/simple-route

```

Usage
-----

[](#usage)

anywhere, ../config/routes.php, for example:

```
return [
    'home'      => ['/', fn() => new HtmlResponse('This is homepage')],
    'about'     => ['/about', AboutHandler::class],
    'auth'      => ['/auth/{action?}' Auth::class],
    'posts'     => ['/posts', [PostController::class, 'list']],
    'post'      => ['/post/{id}/{slug?}', PostController::class, ['slug' => '[\w-]*']],
    'post.save' => ['/post/{id?}', [PostController::class, 'save']],
]
```

anywhere:

```
use Az\Route\Router;
...
$router = new Router(['../config/routes.php', '../module/routes.php']);

if (!$route = $this->router->match($request)) {
    //abort(404)
}

$handler = $route->getInstance($container);
$response = $handler->handle($request);
```

#### When using a dependency container and pipeline

[](#when-using-a-dependency-container-and-pipeline)

In the dependency container:

```
...
use Az\Route\RouterInterface;
use Az\Route\Route;
...

return [
    ...
    RouterInterface::class => fn() => new Router('../config/routes.php'),
    ...
]
```

Add middleware to end of pipeline:

```
...
$this->pipe(RouteMatch::class);
$this->pipe(RouteDispatch::class);
```

Features
--------

[](#features)

- Very simple record for route:

    ```
    'name' => [pattern, handler, tokens],
    'auth' => ['/auth/{action?}', Auth::class]
    ```

    - Each route is named
    - The route can be applied to a function, anonymous function, method, or the entire controller
    - {action} is reserved token name, means the name of a controller method
    - Default controller method name is \_\_invoke
    - Default http request methods is \['HEAD', 'GET'\]
    - The delimeters me be any valid character
- Fine-tuning of the route is done through attributes:

    ```
    ...
    use Az\Route\Route;
    ...
    #[Route(methods: 'any')]
    #[Route(host: 'localhost')]
    class ClassName
    {
      #[Route(filter: 'some_function')]
      #[Route(ajax: false, tokens: ['id' => '\d+'])]
      public function show($id)

      #[Route(methods: ['post', 'patch'])]
      public function save($id = null)
    }
    ```

    - tokens - redefines default token: `'\w*'`
    - methods - redefines request methods
    - host - filter by $request-&gt;getHost() (default - no filter)
    - ajax - filter by 'x\_requested\_with' header (default - no filter)
    - filter - any named function or method, takes the route as the first parameter, and the request as the second ```
        function my_filter(Az\Route\Route $route, ServerRequestInterface $request): bool
        ```
- Request handler (controller) record may be:

    ```
    - fn($arg) => new Request(...)
    - function ($arg1, $arg2) {...}
    - ClassName::class
    - [ClassName::class, 'methodName']
    - 'Ns\ClassName::methodName' or 'Ns\ClassName@methodName'
    - $instance or [$instance, 'methodName']
    ```

    Before invoke the controller is wrapped in class implements RequestHandleInterface. Therefore, we recommend using a controller that implements the RequestHandlerInterface right away
- Router does not create instances of the Route class until match pattern and uri. This saves memory and time.

### Happy use for You!

[](#happy-use-for-you)

**Try the [demo](https://github.com/JackRabbit911/simple-route-demo) for get more examples**

###  Health Score

44

—

FairBetter than 91% of packages

Maintenance91

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity56

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

Every ~51 days

Recently: every ~87 days

Total

9

Last Release

74d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6eca0bc5a858e51896af9cb1d265bb10db18de308c234cd896b99d92c45998d1?d=identicon)[JackRabbit911](/maintainers/JackRabbit911)

---

Top Contributors

[![JackRabbit911](https://avatars.githubusercontent.com/u/6129183?v=4)](https://github.com/JackRabbit911 "JackRabbit911 (87 commits)")

---

Tags

phproutingroute

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/alpha-zeta-simple-route/health.svg)

```
[![Health](https://phpackages.com/badges/alpha-zeta-simple-route/health.svg)](https://phpackages.com/packages/alpha-zeta-simple-route)
```

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.8k18.5M1.6k](/packages/cakephp-cakephp)[neos/flow

Flow Application Framework

862.0M449](/packages/neos-flow)[pecee/simple-router

Simple, fast PHP router that is easy to get integrated and in almost any project. Heavily inspired by the Laravel router.

696214.6k17](/packages/pecee-simple-router)[jaxon-php/jaxon-core

Jaxon is an open source PHP library for easily creating Ajax web applications

73142.3k25](/packages/jaxon-php-jaxon-core)[developermarius/simple-router

Simple, fast PHP router that is easy to get integrated and in almost any project. Heavily inspired by the Laravel router.

112.4k](/packages/developermarius-simple-router)

PHPackages © 2026

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