PHPackages                             jsc-php/routes - 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. jsc-php/routes

ActiveLibrary[API Development](/categories/api)

jsc-php/routes
==============

Attribute based router

056PHP

Since Jun 17Pushed 1mo agoCompare

[ Source](https://github.com/jsc-php/routes)[ Packagist](https://packagist.org/packages/jsc-php/routes)[ RSS](/packages/jsc-php-routes/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

jsc-php/routes
==============

[](#jsc-phproutes)

This package provides a router for handling HTTP requests in PHP applications. It allows you to define routes and associate them with specific controller actions, making it easier to manage and organize your application's routing logic.

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

[](#installation)

```
$ composer require jsc-php/routes

```

### Features

[](#features)

- **Attribute-based routing** – Define routes using modern PHP attributes
- **Priority Based Routing** – Define routes with priority levels for better control
- **Memcached support** – Optional route caching for improved performance
- **URI parameter extraction** – Automatically extract and pass parameters to your methods
- **Automatic discovery** – Scans directories to find and register routes
- **Method filtering** – Restrict routes to specific HTTP methods (GET, POST, etc.)

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

[](#requirements)

- PHP &gt;= 8.5
- ext-zlib
- ext-http
- ext-uri
- ext-memcached

Usage
-----

[](#usage)

Create a 'RouterConfig' instance and pass if to the Router Constructor

```
$router_config = new \JscPhp\Routes\RouterConfig();
$router_config->addDirectory('/path/to/controllers');
$router = new Router($router_config)
$router->go();

```

Note

If you want to use Memcached for caching, ensure Memcached is installed and configured properly

$router\_config-&gt;addMemcachedServer(host: 'localhost', port: 11211);

Host is optional if using localhost Port number is optional if using default port

You can also use setUseMemcached(true); This will add a default memcached server using host 'localhost' and port '11211'

For testing, you can also use setUseMemcached(false) after using addMemcachedServer to disable using Memcached

### Route Attribute

[](#route-attribute)

Add a \\JscPhp\\Routes\\Attr\\Route attribute ot the controller method you want to handle the request

```
use JscPhp\Routes\Attributes\Route;
class Controller {
    #[Route('/post')]
    function post() {...}
}

```

You can define multiple routes by adding addition Route attributes to the same method

```
use JscPhp\Routes\Attributes\Route;
...
#[Route('/post')]
#[Route('/read')]
function getPost() {...}

```

Parameters can be defined it the route path by wrapping them in curly braces.

```
use JscPhp\Routes\Attributes\Route;
...
#[Route('/post/{id}/{page}')]
public function post($id, $page) {...}

```

Adding a question mark to the parameter name makes it optional.

```
#[Route('/post/{id?}')]

```

Adding a pipe &lt;|&gt; to the parameter is optional but can limit the type of values that can be accepted for that parameter.

TypeSymbolDescriptionExampleInteger`i`Matches only integers`{id|i}`Alpha`a`Matches only alphabetic characters`{name|a}`Decimal/Float`d` or `f`Matches decimal numbers`{price|d}````
 use JscPhp\Routes\Attributes\Route;

 #[Route('/hello/{id}')] - Matches /hello/abc123
 #[Route('/hello/{id|i}')] - Matches /hello/123 but not /hello/abc123

```

For custom types, you can use also use a regex expression after the pipe. Do not include parentheses.

```
#[Route('/hello/{id|\d{3}}')] - Matches /hello/123 but not /hello/1234

```

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance59

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/32767854a04a19683365ea864694922d19a0bb8511f4b1d7ecb28500e039e185?d=identicon)[jsc-php](/maintainers/jsc-php)

---

Top Contributors

[![jsc-php](https://avatars.githubusercontent.com/u/41808297?v=4)](https://github.com/jsc-php "jsc-php (61 commits)")

### Embed Badge

![Health badge](/badges/jsc-php-routes/health.svg)

```
[![Health](https://phpackages.com/badges/jsc-php-routes/health.svg)](https://phpackages.com/packages/jsc-php-routes)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35816.5M7](/packages/exsyst-swagger)[lucasdotvin/laravel-soulbscription

A straightforward interface to handle subscriptions and features consumption.

709209.3k](/packages/lucasdotvin-laravel-soulbscription)

PHPackages © 2026

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