PHPackages                             idealogica/route-one - 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. idealogica/route-one

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

idealogica/route-one
====================

PSR-15 route middleware for advanced middleware routing.

0.1.5(1y ago)1737↓87.5%MITPHPPHP &gt;=7.0.0CI failing

Since Jul 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/idealogica/route-one)[ Packagist](https://packagist.org/packages/idealogica/route-one)[ RSS](/packages/idealogica-route-one/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (9)Versions (7)Used By (0)

route-one - PSR-15 route middleware for advanced middleware routing
===================================================================

[](#route-one---psr-15-route-middleware-for-advanced-middleware-routing)

[![route-one](https://raw.githubusercontent.com/idealogica/route-one/master/logo.png "route-one")](https://raw.githubusercontent.com/idealogica/route-one/master/logo.png)

**The package is in the beta stage**

`route-one` is a [PSR-15](https://github.com/http-interop/http-middleware) compatible middleware aimed to flexibly route a request to another middleware based on HTTP request url path, host, http method, etc. It is built on top of [Middleman](https://github.com/mindplay-dk/middleman) and [Aura.Router](https://github.com/auraphp/Aura.Router) packages. It's a good addition to your favorite middleware dispatcher to feel it more likely classical request router. This package also contains a middleware dispatcher that has bunch of useful methods for easy creating route middleware instances.

`route-one` is very similar to classic controller routers from every modern framework, but it has some more advantages:

- Standard compliant. You can use any PSR-15 compatible middleware. For example any of these: [middlewares/psr15-middlewares](https://github.com/middlewares/psr15-middlewares).
- Allows to build multi-dimensional routes and modify response from a group of middleware.
- It makes your code highly reusable. Any part of the web resource can be bundled as a separate packaged middleware and used in other projects.

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

[](#installation)

```
composer require idealogica/route-one:~0.1.0

```

General usage
-------------

[](#general-usage)

```
// general dispatcher

$dispatcher = DispatcherFactory::createDefault()->createDispatcher();

// page layout middleware

$dispatcher->addMiddleware(
    function (ServerRequestInterface $request, DelegateInterface $next) {
        $response = $next->process($request);
        $content = $response->getBody()->getContents();
        return $response
            ->withBody($this->streamFor('' . $content . ''))
            ->withHeader('content-type', 'text/html; charset=utf-8');
    }
);

// blog middleware

$dispatcher->addMiddleware(
    function (ServerRequestInterface $request, DelegateInterface $next) {

        // blog middleware dispatcher

        $blogDispatcher = DispatcherFactory::createDefault()->createDispatcher();
        $blogDispatcher->getDefaultRoute()->setHost('www.test.com')->setSecure(false);

        // blog posts list middleware (path based routing)

        $blogDispatcher->addGetRoute('/blog/posts',
            function (ServerRequestInterface $request, DelegateInterface $next) {
                // stop middleware chain execution
                return new Response($this->streamFor('Posts listPost1Post2'));
            }
        )->setName('blog.list');

        // blog single post middleware (path based routing)

        $blogDispatcher->addGetRoute('/blog/posts/{id}',
            function (ServerRequestInterface $request, DelegateInterface $next) {
                $id = (int)$request->getAttribute('1.id'); // prefix for route-one attributes
                // post id is valid
                if ($id === 1) {
                    // stop middleware chain execution
                    return new Response($this->streamFor(sprintf('Post #%sExample post', $id)));
                }
                // post not found, continue to the next middleware
                return $next->process($request);
            }
        )->setName('blog.post');

        // blog page not found middleware (no routing, executes for each request)

        $blogDispatcher->addMiddleware(
            function (ServerRequestInterface $request, DelegateInterface $next)
            {
                // 404 response
                return new Response($this->streamFor('Page not found'), 404);
            }
        );

        return $blogDispatcher->dispatch($request);
    }
);

// dispatching

$response = $dispatcher->dispatch(
    new ServerRequest(
        [],
        [],
        'http://www.test.com/blog/posts/1',
        'GET'
    )
);

(new SapiEmitter())->emit($response);
```

As you can see you can use callable as middleware. It is not a part of PSR-15 but it can be very helpful for quick prototyping.

Also you can use the route middleware separately with your own dispatcher:

```
$routeFactory = new RouteFactory(
    new AuraRouteMiddleware($basePath),
    new AuraUriGenerator($basePath)
);
$routeMiddleware = $routeFactory->createGetRoute('/blog/posts', $middlewareToRoute);
```

For more information on routing rules configuration please refer to [Aura.Router routes documentation](https://github.com/auraphp/Aura.Router/blob/3.x/docs/defining-routes.md).

Uri generation
--------------

[](#uri-generation)

You can use generator to create URIs based or your named routes. Example for the code above:

```
// route path is '/blog/posts/{id}' for 'blog.post' route
$blogPostUrl = $blogDispatcher->getUriGenerator()->generate('blog.post', ['id' => 100]);
echo($blogPostUrl); // outputs "http://www.test.com/blog/posts/100"
```

For more information on URIs generation please refer to [Aura.Router generator documentation](https://github.com/auraphp/Aura.Router/blob/3.x/docs/generating-paths.md).

License
-------

[](#license)

route-one is licensed under a [MIT License](https://opensource.org/licenses/MIT).

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance45

Moderate activity, may be stable

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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 ~570 days

Recently: every ~712 days

Total

6

Last Release

431d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1dfe693e24f13322ee0ab1de94b76274aa9bedfd1f0951913c44a971ad8d4cb8?d=identicon)[idealogica](/maintainers/idealogica)

---

Top Contributors

[![idealogica](https://avatars.githubusercontent.com/u/15087194?v=4)](https://github.com/idealogica "idealogica (1 commits)")

---

Tags

psr-7middlewarerouterroutingroute

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/idealogica-route-one/health.svg)

```
[![Health](https://phpackages.com/badges/idealogica-route-one/health.svg)](https://phpackages.com/packages/idealogica-route-one)
```

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.8k19.1M1.7k](/packages/cakephp-cakephp)[league/route

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

6673.2M137](/packages/league-route)[mezzio/mezzio

PSR-15 Middleware Microframework

3913.8M120](/packages/mezzio-mezzio)[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28545.4k3](/packages/mezzio-mezzio-authentication-oauth2)[sunrise/http-router

A powerful solution as the foundation of your project.

17450.9k10](/packages/sunrise-http-router)[mezzio/mezzio-authentication

Authentication middleware for Mezzio and PSR-7 applications

131.7M39](/packages/mezzio-mezzio-authentication)

PHPackages © 2026

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