PHPackages                             gyselroth/micro-http - 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. gyselroth/micro-http

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

gyselroth/micro-http
====================

PHP HTTP routing

v0.0.8(6y ago)01.4kMITPHPPHP &gt;=7.1

Since Nov 21Pushed 6y ago1 watchersCompare

[ Source](https://github.com/gyselroth/micro-http)[ Packagist](https://packagist.org/packages/gyselroth/micro-http)[ Docs](http://www.github.com/gyselroth/micro-http)[ RSS](/packages/gyselroth-micro-http/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (8)Dependencies (5)Versions (9)Used By (0)

Lightweight HTTP routing
========================

[](#lightweight-http-routing)

[![Build Status](https://camo.githubusercontent.com/38ae4b89cad42dbedc37319a177e603d8b9e7c36f3dd3af8c11b42af5e4987b5/68747470733a2f2f7472617669732d63692e6f72672f677973656c726f74682f6d6963726f2d687474702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/gyselroth/micro-http)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/20f3d3a0a9fc34e81f1e6a2b9f1a7c50de08f6e16852c65b634307603a91d46f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f677973656c726f74682f6d6963726f2d687474702f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/gyselroth/micro-http/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/423025f67303eed74db11451796136ab208da47e5c8bd2303b9b40573697c09d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f677973656c726f74682f6d6963726f2d687474702e737667)](https://packagist.org/packages/gyselroth/micro-http)[![GitHub release](https://camo.githubusercontent.com/8896ef4c28d1d49be0f475e6c3741e541834409985f240f153c673d9a07dcf17/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f677973656c726f74682f6d6963726f2d687474702e737667)](https://github.com/gyselroth/micro-http/releases)[![GitHub license](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://raw.githubusercontent.com/gyselroth/micro-http/master/LICENSE)

Description
-----------

[](#description)

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

[](#requirements)

The component is only &gt;= PHP7.1 compatible.

Download
--------

[](#download)

The package is available at packagist:

To install the package via composer execute:

```
composer require gyselroth/micro-http

```

Documentation
-------------

[](#documentation)

### Initialize router

[](#initialize-router)

The http router requires an array with http headers, usually this is $\_SERVER and a PSR-3 compatible logger.

```
$router = new \Micro\Http\Router(\Psr\Log\LoggerInterface $logger, array $server, ?\Psr\Container\ContainerInterface);
```

### Adding routes

[](#adding-routes)

```
$router = (new \Micro\Http\Router($logger))
  ->clearRoutingTable()
  ->addRoute(new \Micro\Http\Router\Route('/api/v1/user', 'MyApp\Rest\v1\User'))
  ->addRoute(new \Micro\Http\Router\Route('/api/v1/user/{uid:#([0-9a-z]{24})#}', 'MyApp\Rest\v1\User'))
  ->addRoute(new \Micro\Http\Router\Route('/api/v1$', 'MyApp\Rest\v1\Rest'))
  ->addRoute(new \Micro\Http\Router\Route('/api/v1', 'MyApp\Rest\v1\Rest'))
  ->addRoute(new \Micro\Http\Router\Route('/api$', 'MyApp\Rest\v1\Rest'));
  ->run(array $controller_params);
```

The router tries to map a request to the first matching route in his routing table. The request gets mappend to a class and method. Optional parameters/query string gets automatically submitted to the final controller class.

Given the routing table above and the following final controller class:

```
namespace MyApp\Rest\v1;

class User
{
    /**
     * GET http://localhost/api/v1/user/540f1fc9a641e6eb708b4618/attributes
     * GET http://localhost/api/v1/user/attributes?uid=540f1fc9a641e6eb708b4618
     */
    public function getAttributes(string $uid=null): \Micro\Http\Response
    {

    }

    /**
     * GET http://localhost/api/v1/user/540f1fc9a641e6eb708b4618
     * GET http://localhost/api/v1/user?uid=540f1fc9a641e6eb708b4618
     */
    public function get(string $uid=null): \Micro\Http\Response
    {

    }

    /**
     * POST http://localhost/api/v1/user/540f1fc9a641e6eb708b4618/password / POST body password=1234
     * POST http://localhost/api/v1/user/password?uid=540f1fc9a641e6eb708b4618 / POST body password=1234
     * POST http://localhost/api/v1/user/password / POST body password=1234, uid=540f1fc9a641e6eb708b4618
     */
    public function postPassword(string $uid, string $password): \Micro\Http\Response
    {

    }

    /**
     * DELETE http://localhost/api/v1/user/540f1fc9a641e6eb708b4618/mail
     * DELETE http://localhost/api/v1/user/mail?uid=540f1fc9a641e6eb708b4618
     */
    public function deleteMail(string $uid=null): \Micro\Http\Response
    {

    }

    /**
     * DELETE http://localhost/api/v1/540f1fc9a641e6eb708b4618/mail
     * DELETE http://localhost/api/v1/user?uid=540f1fc9a641e6eb708b4618
     */
    public function delete(string $uid=null): \Micro\Http\Response
    {

    }

    /**
     * HEAD http://localhost/api/v1/user/540f1fc9a641e6eb708b4618
     * HEAD http://localhost/api/v1/user?uid=540f1fc9a641e6eb708b4618
     */
    public function headExists(string $uid=null): \Micro\Http\Response
    {

    }
}
```

### Response

[](#response)

Each endpoint needs to return a Response object to the router.

```
/**
 * HEAD http://localhost/api/v1/user/540f1fc9a641e6eb708b4618
 * HEAD http://localhost/api/v1/user?uid=540f1fc9a641e6eb708b4618
 */
public function headExists(string $uid=null): \Micro\Http\Response
{
  if(true) {
    return (new \Micro\Http\Response())->setCode(200)->setBody('user does exists');
  } else {
    return (new \Micro\Http\Response())->setCode(404);
  }
}
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity53

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

Recently: every ~176 days

Total

8

Last Release

2308d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f7f49cbc31f2166f057acdcb3768366d6783ad6a8e5caf7e5990b21d8bbecf3d?d=identicon)[s-aebischer](/maintainers/s-aebischer)

![](https://www.gravatar.com/avatar/c5faa1a8f30f97714249f80b7594e11976f9740912259431764cf0a622958d05?d=identicon)[danielkleeb](/maintainers/danielkleeb)

---

Top Contributors

[![raffis](https://avatars.githubusercontent.com/u/2376735?v=4)](https://github.com/raffis "raffis (20 commits)")

---

Tags

http-routerphppsr-7http-messagemicrorouter

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/gyselroth-micro-http/health.svg)

```
[![Health](https://phpackages.com/badges/gyselroth-micro-http/health.svg)](https://phpackages.com/packages/gyselroth-micro-http)
```

###  Alternatives

[psr/http-message

Common interface for HTTP messages

7.1k1.0B5.5k](/packages/psr-http-message)[symfony/psr-http-message-bridge

PSR HTTP message bridge

1.3k296.6M804](/packages/symfony-psr-http-message-bridge)[fig/http-message-util

Utility classes and constants for use with PSR-7 (psr/http-message)

39489.0M271](/packages/fig-http-message-util)[league/route

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

6633.1M116](/packages/league-route)[aura/router

Powerful, flexible web routing for PSR-7 requests.

5231.5M67](/packages/aura-router)[sunrise/http-router

A powerful solution as the foundation of your project.

16249.8k10](/packages/sunrise-http-router)

PHPackages © 2026

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