PHPackages                             effectra/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. [HTTP &amp; Networking](/categories/http)
4. /
5. effectra/router

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

effectra/router
===============

The Effectra HTTP Routing package.

v2.1.7(2y ago)1511MITPHP

Since Jun 20Pushed 2y agoCompare

[ Source](https://github.com/effectra/router)[ Packagist](https://packagist.org/packages/effectra/router)[ RSS](/packages/effectra-router/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (8)Versions (12)Used By (1)

Effectra Router Library
=======================

[](#effectra-router-library)

Effectra PHP Router is a lightweight and flexible routing library for PHP applications. It provides a convenient way to define routes and dispatch incoming requests to the appropriate controllers or callbacks.

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

[](#installation)

You can install the Effectra PHP Router library via Composer. Run the following command in your project directory:

```
composer require effectra/router

```

Usage
-----

[](#usage)

To get started with Effectra PHP Router, follow these steps:

1. Include the autoloader if you haven't already done so:

```
require_once 'vendor/autoload.php';
```

2. Import the necessary classes:

```
use Effectra\Router\Route;
use Effectra\Router\RouteGroup;

use Effectra\Http\Foundation\RequestFoundation;
use Effectra\Http\Message\Response;

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
```

3. Create an instance of the `Route` class:

```
//pass response class to the router
$response = new Response();

$route = new Route($response);
```

4. Define routes using the available methods:

```
$route->get('/home', function () {
    return 'Welcome to the home page!';
});

$route->post('/contact', 'StaticController@login');

$router->get('/', [HomeController::class, 'index']);

$router->get('/users/', [UserController::class, 'index']);

$router->post('/signin', function (RequestInterface $request, ResponseInterface $response) {
    return $response->json([
        'message' => 'hello world'
    ]);
});

$route->crud('/report', ReportController::class, 'read|readOne|create|delete|deleteAll|search');

$route->auth('/auth/', AuthController::class);

$route->group('/file/upload/', UploadController::class, function(RouteGroup $router){
    $router->post('audio','createAudio');
    $router->post('video','createVideo');
});
```

5. Dispatch the incoming request:

```
$request = RequestFoundation::createFromGlobals();

$route->dispatch($request);
```

### Route Methods

[](#route-methods)

The `Route` class provides several methods to define routes:

- `get($pattern, $callback)`: Defines a GET route.
- `post($pattern, $callback)`: Defines a POST route.
- `put($pattern, $callback)`: Defines a PUT route.
- `delete($pattern, $callback)`: Defines a DELETE route.
- `patch($pattern, $callback)`: Defines a PATCH route.
- `options($pattern, $callback)`: Defines an OPTIONS route.
- `any($pattern, $callback)`: Defines a route that matches any HTTP method.
- `register($method, $pattern, $callback)`: Defines a custom route with a specific HTTP method.
- `routes()`: Returns an array of defined routes.

### Middleware

[](#middleware)

The `Route` class supports middleware for route groups. You can use the `middleware` method to add middleware to a group of routes:

```
$router->get('/users/{id}', [UserController::class, 'show'])->middleware(new AuthMiddleware());
```

### Error Handling

[](#error-handling)

The `Route` class provides methods to handle 404 Not Found and 500 Internal Server Error responses:

```
$route->setNotFound(function () {
    // Handle 404 Not Found response
});

$route->setInternalServerError(function () {
    // Handle 500 Internal Server Error response
});
```

Contributing
------------

[](#contributing)

Contributions to the Effectra PHP Router library are welcome! If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.

License
-------

[](#license)

The Effectra PHP Router library is open-source software licensed under the [MIT license](https://opensource.org/licenses/MIT).

---

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

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

Recently: every ~28 days

Total

11

Last Release

934d ago

Major Versions

v1.0.0 → v2.0.02023-06-29

### Community

Maintainers

![](https://www.gravatar.com/avatar/7e6219ae87e98df8783b2f595b013035dd183c0712afd24045a8acf0a40c3bdf?d=identicon)[effectra](/maintainers/effectra)

---

Top Contributors

[![BMTmohammedtaha](https://avatars.githubusercontent.com/u/95439605?v=4)](https://github.com/BMTmohammedtaha "BMTmohammedtaha (32 commits)")

---

Tags

httpmiddlewarephppsrpsr-15psr-7router

### Embed Badge

![Health badge](/badges/effectra-router/health.svg)

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

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.9k19.5M1.8k](/packages/cakephp-cakephp)[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.1B4.0k](/packages/guzzlehttp-psr7)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[typo3/cms-core

TYPO3 CMS Core

3713.2M5.1k](/packages/typo3-cms-core)[sunrise/http-router

A powerful solution as the foundation of your project.

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

PHPackages © 2026

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