PHPackages                             chi-teck/micro-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. chi-teck/micro-router

ActiveLibrary

chi-teck/micro-router
=====================

Micro router

1.x-dev(5y ago)37MITPHPPHP ^8.0

Since Jan 17Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Chi-teck/micro-router)[ Packagist](https://packagist.org/packages/chi-teck/micro-router)[ RSS](/packages/chi-teck-micro-router/feed)WikiDiscussions 1.x Synced 4d ago

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

Micro Router
============

[](#micro-router)

A simple and fast routing system for PSR-7 requests.

Requirements
------------

[](#requirements)

- PHP 8.0+
- [psr/http-message provider](https://packagist.org/providers/psr/http-message-implementation)
- [psr/simple-cache provider](https://packagist.org/providers/psr/simple-cache-implementation)

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

[](#installation)

```
composer require chi-teck/micro-router
```

Usage
-----

[](#usage)

### Define routes

[](#define-routes)

```
$routes = new RouteCollection();

$routes['article.view'] = new Route(
    methods: ['GET'],
    path: '/article/{id}',
    requirements: ['id' => '\d+'],
    handler: ArticleViewHandler::class,
);

$routes['article.update'] = new Route(
    methods: ['PUT'],
    path: '/article/{id}',
    requirements: ['id' => '\d+'],
    handler: ArticleUpdateHandler::class,
);

$routes['article.delete'] = new Route(
    methods: ['DELETE'],
    path: '/article/{id}',
    requirements: ['id' => '\d+'],
    handler: ArticleDeleteHandler::class,
);

$routes['article.create'] = new Route(
    methods: ['POST'],
    path: '/article',
    handler: ArticleCreateHandler::class,
);
```

Alternatively, the routes can be defined via `create` factory method.

```
$routes = new RouteCollection();
$routes['article.view'] = Route::create('GET', '/article/{id:\d+}', ArticleViewHandler::class);
$routes['article.update'] = Route::create('PUT', '/article/{id:\d+}', ArticleUpdateHandler::class);
$routes['article.delete'] = Route::create('DELETE', '/article/{id:\d+}', ArticleDeleteHandler::class);
$routes['article.create'] = Route::create('POST', '/article', ArticleCreateHandler::class);
```

Handle request
--------------

[](#handle-request)

```
use MicroRouter\Contract\Exception\MethodNotAllowedInterface;
use MicroRouter\Contract\Exception\ResourceNotFoundInterface;
use MicroRouter\Matcher;

/** @var \MicroRouter\Contract\RouteCollectionInterface $routes */
$routes = require __DIR__ . '/path/to/routes.php';

/** @var \Psr\SimpleCache\CacheInterface $cache */
$matcher = Matcher::create($cache);

/** @var \Psr\Http\Message\ServerRequestFactoryInterface $request_factory */
// In real application the request is created from PHP super globals.
$request = $request_factory->createServerRequest('GET', '/article/123');
try {
    $result = $matcher->match($request, $routes);
    $handler = $result->getRoute()->getHandler();
    // Depending on handler type (closure, service ID, etc) you may need to
    // resolve the callable before invoking.
    $response = $handler(...$result->getParameters());
}
catch (ResourceNotFoundInterface) {
    /** @var \Psr\Http\Message\ResponseFactoryInterface $response_factory */
    $response = $response_factory->createResponse(404);
}
catch (MethodNotAllowedInterface $exception) {
    /** @var \Psr\Http\Message\ResponseFactoryInterface $response_factory */
    $response = $response_factory->createResponse(405)
        ->withHeader('Allowed', $exception->getAllowedMethods());
}
```

License
-------

[](#license)

MIT License.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

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

Total

4

Last Release

1939d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/673139?v=4)[Ivan](/maintainers/chi-teck)[@Chi-teck](https://github.com/Chi-teck)

---

Top Contributors

[![Chi-teck](https://avatars.githubusercontent.com/u/673139?v=4)](https://github.com/Chi-teck "Chi-teck (20 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/chi-teck-micro-router/health.svg)

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

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.8k18.5M1.6k](/packages/cakephp-cakephp)[algolia/algoliasearch-client-php

API powering the features of Algolia.

69333.0M114](/packages/algolia-algoliasearch-client-php)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[thecodingmachine/graphqlite

Write your GraphQL queries in simple to write controllers (using webonyx/graphql-php).

5723.1M30](/packages/thecodingmachine-graphqlite)[moonshine/moonshine

Laravel administration panel

1.3k217.1k59](/packages/moonshine-moonshine)[laudis/neo4j-php-client

Neo4j-PHP-Client is the most advanced PHP Client for Neo4j

184616.9k31](/packages/laudis-neo4j-php-client)

PHPackages © 2026

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