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

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

innmind/router
==============

HTTP router

6.0.0(4mo ago)015.4k↓76.4%12MITPHPPHP ~8.4CI passing

Since Aug 5Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/Innmind/Router)[ Packagist](https://packagist.org/packages/innmind/router)[ Docs](http://github.com/Innmind/Router)[ RSS](/packages/innmind-router/feed)WikiDiscussions develop Synced 3d ago

READMEChangelog (10)Dependencies (7)Versions (20)Used By (2)

Router
======

[](#router)

[![codecov](https://camo.githubusercontent.com/3bf97d8d6d1d8221c85ffd750eb8c62b7f209ad6f1cfb427d62dc63746421c11/68747470733a2f2f636f6465636f762e696f2f67682f496e6e6d696e642f526f757465722f6272616e63682f646576656c6f702f67726170682f62616467652e7376673f6272616e63683d6d6173746572)](https://codecov.io/gh/Innmind/Router)[![Build Status](https://github.com/Innmind/Router/workflows/CI/badge.svg)](https://github.com/Innmind/Router/actions?query=workflow%3ACI)[![Type Coverage](https://camo.githubusercontent.com/cf915c3d677370a046b5095cdfbb4432712dadd6d29fb0827ac054745353c43b/68747470733a2f2f73686570686572642e6465762f6769746875622f496e6e6d696e642f526f757465722f636f7665726167652e737667)](https://shepherd.dev/github/Innmind/Router)

Monadic HTTP router.

Note

This package has been heavily inspired from [F# Giraffe](https://github.com/giraffe-fsharp/Giraffe).

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

[](#installation)

```
composer require innmind/router
```

Usage
-----

[](#usage)

```
use Innmind\Router\{
    Router,
    Any,
    Method,
    Endpoint,
    Handle,
};
use Innmind\Http\{
    ServerRequest,
    Response,
    Response\StatusCode,
};
use Innmind\Immutable\Attempt;

$router = Router::of(
    Any::of(
        Method::post()
            ->pipe(Endpoint::of('/url{/template}'))
            ->pipe(Handle::of(static fn(ServerRequest $request, string $template) => Attempt::result(Response::of(
                StatusCode::ok,
                $request->protocolVersion(),
            )))),
        Method::delete()
            ->pipe(Endpoint::of('/resource/{id}'))
            ->pipe(Handle::of(static fn(ServerRequest $request, string $id) => Attempt::result(Response::of(
                StatusCode::ok,
                $request->protocolVersion(),
            )))),
    ),
);

$response = $router(/* instance of ServerRequest */)->unwrap(); // Response
```

This example can be simplified as:

```
use Innmind\Router\{
    Router,
    Pipe,
};
use Innmind\Http\{
    ServerRequest,
    Response,
    Response\StatusCode,
};
use Innmind\Immutable\Attempt;

$pipe = Pipe::new();
$router = Router::of(
    $pipe->any(
        $pipe
            ->post()
            ->endpoint('/url{/template}')
            ->spread()
            ->handle(static fn(ServerRequest $request, string $template) => Attempt::result(
                Response::of(
                    StatusCode::ok,
                    $request->protocolVersion(),
                ),
            )),
        $pipe
            ->delete()
            ->endpoint('/resource/{id}')
            ->spread()
            ->handle(static fn(ServerRequest $request, string $id) => Attempt::result(
                Response::of(
                    StatusCode::ok,
                    $request->protocolVersion(),
                ),
            )),
    ),
);

$response = $router(/* instance of ServerRequest */)->unwrap(); // Response
```

### Building a simple app

[](#building-a-simple-app)

Example using the [`innmind/http-server`](https://github.com/Innmind/HttpServer/) package to respond with files stored in a private folder.

```
use Innmind\Router\{
    Router,
    Any,
    Method,
    Endpoint,
    Handle,
};
use Innmind\HttpServer\Main;
use Innmind\OperatingSystem\OperatingSystem;
use Innmind\Http\{
    ServerRequest,
    Response,
    Response\StatusCode,
};
use Innmind\Filesystem\Name;
use Innmind\Url\Path;

new class extends Main {
    private Router $router;

    protected function preload(OperatingSystem $os): void
    {
        $this->router = Router::of(Any::of(
            Method::get()
                ->pipe(Endpoint::of('/image/{name}'))
                ->pipe(Handle::of(static fn(string $name) => self::loadFile(
                    $os,
                    $name,
                ))),
            Method::get()
                ->pipe(Endpoint::of('/image/random'))
                ->pipe(Handle::of(static fn() => self::loadFile(
                    $os,
                    generateRandomName(),
                ))),
        ));
    }

    protected function main(ServerRequest $request): Response
    {
        return ($this->router)($request)->match(
            static fn($response) => $response,
            static fn() => Response::of(
                StatusCode::notFound,
                $request->protocolVersion(),
            ),
        );
    }

    private function loadFile(OperatingSystem $os, string $name): Response
    {
        return $os
            ->filesystem()
            ->mount(Path::of('some/private/folder/'))
            ->unwrap()
            ->get(Name::of($name))
            ->match(
                static fn($file) => Response::of(
                    StatusCode::ok,
                    $request->protocolVersion(),
                    null,
                    $file->content(),
                ),
                static fn() => Response::of(
                    StatusCode::notFound,
                    $request->protocolVersion(),
                ),
            );
    }
}
```

###  Health Score

56

—

FairBetter than 97% of packages

Maintenance79

Regular maintenance activity

Popularity25

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity89

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 99.4% 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 ~171 days

Recently: every ~44 days

Total

17

Last Release

146d ago

Major Versions

1.1.0 → 2.0.02020-02-01

2.1.0 → 3.0.02022-12-18

3.4.0 → 4.0.02023-11-01

4.1.0 → 5.0.02025-08-15

5.2.0 → 6.0.02026-02-08

PHP version history (6 changes)1.0.0PHP ~7.2

2.0.0PHP ~7.4

2.1.0PHP ~7.4|~8.0

3.0.0PHP ~8.1

3.4.0PHP ~8.2

6.0.0PHP ~8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/851425?v=4)[Baptiste Langlade](/maintainers/Baptouuuu)[@Baptouuuu](https://github.com/Baptouuuu)

---

Top Contributors

[![Baptouuuu](https://avatars.githubusercontent.com/u/851425?v=4)](https://github.com/Baptouuuu "Baptouuuu (166 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

---

Tags

httprouter

### Embed Badge

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

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

###  Alternatives

[middlewares/fast-route

Middleware to use FastRoute

98205.1k15](/packages/middlewares-fast-route)[sunrise/http-router

A powerful solution as the foundation of your project.

17451.6k10](/packages/sunrise-http-router)[miladrahimi/phprouter

A powerful, lightweight, and very fast HTTP URL router for PHP projects.

20634.2k2](/packages/miladrahimi-phprouter)[amphp/http-server-router

Routes to request handlers based on HTTP method and path for amphp/http-server.

39539.2k37](/packages/amphp-http-server-router)[aphiria/aphiria

The Aphiria framework

1428.2k2](/packages/aphiria-aphiria)[wilaak/radix-router

High-performance radix tree based HTTP request router

616.0k5](/packages/wilaak-radix-router)

PHPackages © 2026

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