PHPackages                             apex/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. apex/router

ActivePackage[Utility &amp; Helpers](/categories/utility)

apex/router
===========

Light weight, straight forward router

1.0.1(2y ago)2381MITPHPPHP &gt;=8.1

Since Jan 31Pushed 2y ago1 watchersCompare

[ Source](https://github.com/apexpl/router)[ Packagist](https://packagist.org/packages/apex/router)[ Docs](https://apexpl.io)[ RSS](/packages/apex-router/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (10)Versions (3)Used By (1)

Apex Router
===========

[](#apex-router)

Light weight, easy to understand and use HTTP router that also comes fully and optionally integrated with the [Syrus template engine](https://github.com/apexpl/syrus/), essentially turning it into a cool little micro framework. Not meant for heavy lifting, but excellent if you just need something well structured up and running quickly. Supports the following:

- Simplistic YAML file to define routes which supports partial and full matching paths, dynamic path parameters, and multiple hostnames.
- Fully supports PSR15 and PSR7, and uses middleware classes for forwarding of all HTTP requests.
- All middleware classes fully support both, attribute and constructor based dependancy injection via the [Apex Container](https://github.com/apexpl/container).
- Optional built-in integration with the [Syrus Template Engine](https://github.com/apexpl/syrus/), allowing for auto-routing / mapping of templates, a separate PHP file with each template, and HTTP method-specific PHP functions within each PHP class.

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

[](#installation)

Install via Composer with:

> `composer require apex/router`

Table of Contents
-----------------

[](#table-of-contents)

1. [Base Configuration](https://github.com/apexpl/router/blob/master/docs/config.md)
2. [Routes YAML File](https://github.com/apexpl/router/blob/master/docs/routes.md)
3. [Middleware Classes](https://github.com/apexpl/router/blob/master/docs/middleware.md)
4. [Router Functions](https://github.com/apexpl/router/blob/master/docs/functions.md)
5. [Syrus Template Engine Integration](https://github.com/apexpl/router/blob/master/docs/syrus.md)

Basic Usage
-----------

[](#basic-usage)

For a quick example, check the [example.php](https://github.com/apexpl/router/blob/master/example.php) script that comes with this package.

First, add some routes to your YAML file:

```
routes:
    default: Syrus
    members: MembersArea
    contact$: ContactPage
    "product/:category/:product_id": PathParamsExample

```

```
use Apex\Router\Router;
use Nyholm\Psr7Server\ServerRequestCreator;
use Nyholm\Psr7\Factory\Psr17Factory;
use League\Uri\Http;

require_once("./vendor/autoload.php");

// Define a uri to test with
$uri = Http::createFromString("http://example.com/category/cars");

// Generate PSR7 compliant server request object
$factory = new Psr17Factory();
$creator = new ServerRequestCreator($factory, $factory, $factory, $factory);
$request = $creator->fromGlobals()->withUri($uri);

// Handle http request via router
$router = new Router();
$response = $router->handle($request);

// If this is handled via Syrus auto-routing, the
// HTML would have already been output to the user.
// Otherwise, $response is a PSR7 ResponseInterface object.

// Alternatively, we can use the lookup method
$response = $router->lookup($request);

// This simply determines the route, obtains any dynamic path parameters,
// and instantiates the middleware, but does not execute the process() method within it.
// Instead, $response is a Apex\Router\RouterResponse instance.

// Now, to execute the middle wear and output:
$router->execute($response, true);
```

Support
-------

[](#support)

If you have any questions, issues or feedback, please feel free to drop a note on the [ApexPl Reddit sub](https://reddit.com/r/apexpl/) for a prompt and helpful response.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

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

Total

2

Last Release

904d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4fe486d2ed7db571c0519bb0d52b08b5e953a911936e87331e736a381ef96f29?d=identicon)[apex](/maintainers/apex)

---

Top Contributors

[![apexpl](https://avatars.githubusercontent.com/u/56146521?v=4)](https://github.com/apexpl "apexpl (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[getgrav/grav

Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS

15.6k86.4k1](/packages/getgrav-grav)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[cakephp/cakephp

The CakePHP framework

8.9k19.5M1.8k](/packages/cakephp-cakephp)[jaxon-php/jaxon-core

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

74149.4k30](/packages/jaxon-php-jaxon-core)[bref/bref

Bref is a framework to write and deploy serverless PHP applications on AWS Lambda.

3.4k10.6M67](/packages/bref-bref)[typo3/cms-core

TYPO3 CMS Core

3713.2M5.1k](/packages/typo3-cms-core)

PHPackages © 2026

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