PHPackages                             hq9000/php-rest-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. [API Development](/categories/api)
4. /
5. hq9000/php-rest-router

ActiveLibrary[API Development](/categories/api)

hq9000/php-rest-router
======================

A framework for building REST API structures

1.0.9(5y ago)0215[2 issues](https://github.com/hq9000/php_rest_router/issues)PHPPHP ^5.5|7.\*CI failing

Since Sep 8Pushed 5y agoCompare

[ Source](https://github.com/hq9000/php_rest_router)[ Packagist](https://packagist.org/packages/hq9000/php-rest-router)[ RSS](/packages/hq9000-php-rest-router/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (1)Versions (13)Used By (0)

PHP REST router
===============

[](#php-rest-router)

A simple opinionated PHP framework for building API structures.

Motivation
----------

[](#motivation)

In one of the proprietary projects I was working on, we needed to have a huge and complex REST api surface. Due to its dynamic nature and deep branching, it was considered suboptimal to go the normal "method per action" way.

What was needed is to be able to define a certain meta-structure and have the endpoints be just as a reflection of it.

Main concepts
-------------

[](#main-concepts)

The main concepts of the framework are the ones of:

- a structure (a tree of nodes)
- node traversing

### Structure (a tree of nodes)

[](#structure-a-tree-of-nodes)

A `Structure` is represented by `hq9000\PhpRestRouter\Structure` class.

[![image](https://user-images.githubusercontent.com/21345604/93168690-2899a100-f72c-11ea-8057-523bc74d9577.png)](https://user-images.githubusercontent.com/21345604/93168690-2899a100-f72c-11ea-8057-523bc74d9577.png)

`Structure` is a unidirectional, acyclic graph of `Nodes`.

Each node, except the root one, has exactly one input node.

**note:** the arrows on the diagram above rather show the direction of the traversing, and not the direction of association.

Also, every node has associated:

- path processor - something that is responsible for gathering a piece of information relevant to this node
- path trigger - something that will make node traversing choose this node instead of its sibling.
    - if a node is the only output of its upstream node, the trigger can be omitted

### Node traversing

[](#node-traversing)

The useful thing a structure makes possible is ability to traverse it.

Traversing is done by calling its `public function trace($path, &$dataAccumulator)`, where:

- `path` is a string representing an API endpoint
- `dataAccumulator` is a passed-by-reference array that will be used by `path processors` to put information extracted from the path at each visited node.

The ultimate goal of traversing is to come up with two things:

- the final node
- the fully populated accumulator array

the user of the framework may want to associate certain logic with these bits of information, but this is intentionally left out of scope of the framework.

### Usage Example

[](#usage-example)

This chapter gives a bit of human-readable explanation to complement reading the source code of `CommonTest.php`.

In that test, we pretend that the useful thing nodes can do is to hold certain `tags`. For that, we extend the Node class by `DomainNode`:

```
/*
 * Here in test we use a simple subclass of a Node modeling some "Domain" class doing
 * something actually useful. This one can hold some "tag", in reality,
 * it might, for instance, be able to handle a web request etc.
 */
class DomainNode extends Node
{

    /**
     * @var
     */
    private $tag;

    public function getTag()
    {
        return $this->tag;
    }

    public function setTag($tag)
    {
        $this->tag = $tag;
        return $this;
    }
}
```

The structure of these nodes is shown on the simplified diagram below:

[![image](https://user-images.githubusercontent.com/21345604/93170671-4f59d680-f730-11ea-8f36-9c221df72fde.png)](https://user-images.githubusercontent.com/21345604/93170671-4f59d680-f730-11ea-8f36-9c221df72fde.png)

The test itself performs the "tracings" and checks their results, for example that `class2/123123` results in the `$idNode` found as the final one and the data array appropriatelly populated with

```
{
  "class": "class2",
  "id": 123123
}
```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity65

Established project with proven stability

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

Recently: every ~264 days

Total

10

Last Release

2113d ago

PHP version history (3 changes)1.0.0PHP ^5.3.3 || ^7.0

1.0.1PHP ^5.5

1.0.9PHP ^5.5|7.\*

### Community

Maintainers

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

---

Top Contributors

[![hq9000](https://avatars.githubusercontent.com/u/21345604?v=4)](https://github.com/hq9000 "hq9000 (17 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hq9000-php-rest-router/health.svg)

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

74513.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

265103.1M454](/packages/google-gax)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)

PHPackages © 2026

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