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
==============

Maps a http request to a class method using attributes.

054PHP

Since May 27Pushed 3w 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 3w 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

23

—

LowBetter than 26% of packages

Maintenance62

Regular maintenance activity

Popularity10

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 (60 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.3M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24015.5M18](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172437.8k11](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93452.6k6](/packages/botman-driver-telegram)

PHPackages © 2026

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