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

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

northwoods/router
=================

Fast router for PSR-15 request handlers

1.1.0(7y ago)161.4kMITPHPPHP ^7.1

Since Nov 6Pushed 7y ago1 watchersCompare

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

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

Northwoods Router
=================

[](#northwoods-router)

[![Build Status](https://camo.githubusercontent.com/bb50a3601a3541bbcf0a81dd7d05818ac1947387245c6dec2070914a54ee3ae5/68747470733a2f2f7472617669732d63692e636f6d2f6e6f727468776f6f64732f726f757465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/northwoods/router)[![Code Quality](https://camo.githubusercontent.com/883006aefd181755c601851e7c2528c48ecd31670f28aff9a7b2154e52f08339/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e6f727468776f6f64732f726f757465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/northwoods/router/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/7d75379886c10fc2a2264c468c53e5fef23b6cbd2d08992fca1181c3e9ebef3f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e6f727468776f6f64732f726f757465722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/northwoods/router/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/e7b79e3e78e7484f51951e55adec0eb7005db890d296d52842fb6cfa83267296/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6f727468776f6f64732f726f757465722e7376673f7374796c653d666c6174)](https://packagist.org/packages/northwoods/router)[![Total Downloads](https://camo.githubusercontent.com/ad05dec51ffbe59b92fed0e7f8fa3c7719b360486ee8f79e85dbc5abf205788d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e6f727468776f6f64732f726f757465722e7376673f7374796c653d666c6174)](https://packagist.org/packages/northwoods/router)[![License](https://camo.githubusercontent.com/816026524fb009245ce68f4013737cc82e1c81a7d3f0dee0c8435ac044fe9f1d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6e6f727468776f6f64732f726f757465722e7376673f7374796c653d666c6174)](https://packagist.org/packages/northwoods/router)

A [FastRoute](https://github.com/nikic/FastRoute) based router designed to be used with [PSR-15 middleware](https://www.php-fig.org/psr/psr-15/).

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

[](#installation)

The best way to install and use this package is with [composer](http://getcomposer.org/):

```
composer require northwoods/router
```

Usage
-----

[](#usage)

The router implements `MiddlewareInterface` and can be used with any middleware dispatcher, such as [Broker](https://github.com/northwoods/broker).

```
use Northwoods\Router\Router;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

$router = new Router();
$router->get('user.list', '/users', $userList);
$router->get('user.detail', '/users/{id:\d+}', $userDetail);
$router->post('user.create', '/users', $userCreate);

assert($router instanceof Psr\Http\Server\MiddlewareInterface);
```

This is the preferred usage of the router, as it ensures that the request is properly set up for the route handler. Generally the router should be the last middleware in the stack.

If you prefer to use the router without middleware, the router also implements `RequestHandlerInterface` and can be used directly:

```
/** @var ServerRequestInterface */
$request = /* create server request */;

/** @var ResponseInterface */
$response = $router->handle($request);
```

### Route Handlers

[](#route-handlers)

All route handlers MUST implement the `RequestHandlerInterface` interface:

```
namespace Acme;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

class UserListHandler implements RequestHandlerInterface
{
    public function handle(ServerRequestInterface $request): ResponseInterface
    {
        /** @var array */
        $users = /* load from database, etc */;

        return new Response(200, ['content-type' => 'application-json'], json_encode($users));
    }
}
```

If it is preferable to lazy load handlers, the [lazy-middleware](https://github.com/northwoods/lazy-middleware)package can be used:

```
use Northwoods\Middleware\LazyHandlerFactory;

/** @var LazyHandlerFactory */
$lazyHandler = /* create the factory */;

$router->post('user.create', '/users', $lazyHandler->defer(CreateUserHandler::class));
```

### Reverse Routing

[](#reverse-routing)

Reverse routing enables generating URIs from routes:

```
$uri = $router->uri('user.detail', ['id' => 100]);

assert($uri === '/users/100');
```

API
---

[](#api)

### Router::add($name, $route);

[](#routeraddname-route)

Add a fully constructed route.

### Router::get($name, $pattern, $handler)

[](#routergetname-pattern-handler)

Add a route that works for HTTP GET requests.

### Router::post($name, $pattern, $handler)

[](#routerpostname-pattern-handler)

Add a route that works for HTTP POST requests.

### Router::put($name, $pattern, $handler)

[](#routerputname-pattern-handler)

Add a route that works for HTTP PUT requests.

### Router::patch($name, $pattern, $handler)

[](#routerpatchname-pattern-handler)

Add a route that works for HTTP PATCH requests.

### Router::delete($name, $pattern, $handler)

[](#routerdeletename-pattern-handler)

Add a route that works for HTTP DELETE requests.

### Router::head($name, $pattern, $handler)

[](#routerheadname-pattern-handler)

Add a route that works for HTTP HEAD requests.

### Router::options($name, $pattern, $handler)

[](#routeroptionsname-pattern-handler)

Add a route that works for HTTP OPTIONS requests.

### Router::process($request, $handler)

[](#routerprocessrequest-handler)

Dispatch routing as a middleware.

If no route is found, the `$handler` will be used to generate the response.

### Router::handle($request)

[](#routerhandlerequest)

Dispatch routing for a request.

If no route is found, a response with a HTTP 404 status will be returned.

If a route is found, but it does not allow the request method, a response with a HTTP 405 will be returned.

Credits
-------

[](#credits)

Borrows some ideas from [zend-expressive-fastroute](https://github.com/zendframework/zend-expressive-fastroute) for handling [reverse routing](https://github.com/zendframework/zend-expressive-fastroute/pull/32).

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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

Total

2

Last Release

2746d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/38203?v=4)[Woody Gilk](/maintainers/shadowhand)[@shadowhand](https://github.com/shadowhand)

---

Top Contributors

[![shadowhand](https://avatars.githubusercontent.com/u/38203?v=4)](https://github.com/shadowhand "shadowhand (8 commits)")

---

Tags

handlerhttppsr-15requestserverhttprequestpsr-7middlewarerouterpsr7handlerpsr-15fastpsr15

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[league/route

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

6633.1M115](/packages/league-route)[middlewares/request-handler

Middleware to execute request handlers

451.6M26](/packages/middlewares-request-handler)[middlewares/fast-route

Middleware to use FastRoute

96191.1k15](/packages/middlewares-fast-route)[prooph/http-middleware

http middleware for prooph components

1145.0k](/packages/prooph-http-middleware)[middlewares/error-handler

Middleware to handle http errors

14104.2k13](/packages/middlewares-error-handler)

PHPackages © 2026

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