PHPackages                             artkoder/peasy-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. artkoder/peasy-router

ActiveLibrary[API Development](/categories/api)

artkoder/peasy-router
=====================

A simple, easy to use, and opinionated router for PHP

v0.1.3(2mo ago)06MITPHPPHP &gt;=7.4

Since Sep 23Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/musciencia/peasy)[ Packagist](https://packagist.org/packages/artkoder/peasy-router)[ Docs](https://github.com/musciencia/peasy.git)[ RSS](/packages/artkoder-peasy-router/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (4)Used By (0)

Peasy Router
============

[](#peasy-router)

Peasy Router is an **easy peasy** and opinionated router for PHP. It is meant to be used with small projects that need a very basic ruting functionality. Nothing complicated.

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

[](#installation)

### Using composer

[](#using-composer)

```
composer require artkoder/peasy-router
```

Configure your .htaccess file
-----------------------------

[](#configure-your-htaccess-file)

Add the following code to your `.htaccess` inside a public folder at the same level as your `index.php`.

```

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

```

Setting `index.php`
-------------------

[](#setting-indexphp)

```
// public/index.php
require_once __DIR__ . '/../vendor/autoload.php';

use ArtKoder\Peasy\Http\Router;

// You need to pass the path to your routes directory
$router = new Router('/path/to/routes/directory');

$router->handleRequest();
```

Routes
------

[](#routes)

You can define your routes inside a directory. You can use either a text file with extension `.routes` or a normal `.php` file. Peasy router will scan all the route files inside the directory recursivelly. You can use either of the file formats or combine both if you so desire.

### Defining your routes using a `.routes` file

[](#defining-your-routes-using-a-routes-file)

Here is a sample `web.routes` file:

```
name: budget-report
path: /budget/{start}/{end}
method: get
controller: ArtKoder\Peasy\Controllers\Budget::report

name: budget-index
path: /budget
method: get
controller: ArtKoder\Peasy\Controllers\Budget::index
```

### Defining your routes using a `.php` file

[](#defining-your-routes-using-a-php-file)

The previous routes can alternatively be defined in a `.php` file as follows:

```
// web.php
return [
    [
        'name' => 'budget-report',
        'path' => '/budget/{start}/{end}',
        'method' => 'get',
        'controller' => 'ArtKoder\Peasy\Controllers\Budget::report'
    ],
    [
        'name' => 'budget-index',
        'path' => '/budget',
        'method' => 'get',
        'controller' => 'ArtKoder\Peasy\Controllers\Budget::index'
    ]
];
```

Controllers
-----------

[](#controllers)

Once you have your route definitions, you can create the controllers for your paths.

Here is an example using the previous route definitions:

```
// src/Controllers/Budget.php

namespace ArtKoder\Peasy\Controllers;

class Budget
{
    public static function report($start, $end)
    {
        echo "start: $start\n";
        echo "end: $end\n";
    }

    public static function index()
    {
        echo "Budget index\n";
    }
}
```

### Query parameters

[](#query-parameters)

Peasy router maps all query parameters as arguments to the controllers function. So, if you request the following path: `https://peasy.test/budget/2023-09-01/2023-12-31?var=value`, the controller will expect to get a variable `$var`, so you need to declare it. To avoid errors when a query parameter is not present, you can make variables optional.

Here is an example:

```
// src/Controllers/Budget.php

namespace ArtKoder\Peasy\Controllers;

class Budget
{
    public static function report($start, $end, $var = '')
    {
        echo "start: $start\n";
        echo "end: $end\n";
        echo "var: $var\n";
    }

    public static function index()
    {
        echo "Budget index\n";
    }
}
```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance82

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

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.

###  Release Activity

Cadence

Every ~439 days

Total

3

Last Release

89d ago

### Community

Maintainers

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

---

Top Contributors

[![musciencia](https://avatars.githubusercontent.com/u/28911391?v=4)](https://github.com/musciencia "musciencia (15 commits)")

---

Tags

routerroutingroute

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[phroute/phroute

Fast, fully featured restful request router for PHP

739462.1k29](/packages/phroute-phroute)[aura/router

Powerful, flexible web routing for PSR-7 requests.

5231.5M67](/packages/aura-router)[pecee/simple-router

Simple, fast PHP router that is easy to get integrated and in almost any project. Heavily inspired by the Laravel router.

696214.6k17](/packages/pecee-simple-router)[pmjones/auto-route

Automatically routes HTTP request to action classes.

20158.6k6](/packages/pmjones-auto-route)[contributte/api-router

RESTful Router for your Apis in Nette Framework - created either directly or via attributes

20802.8k3](/packages/contributte-api-router)[tobion/openapi-symfony-routing

Loads routes in Symfony based on OpenAPI/Swagger annotations

4219.5k](/packages/tobion-openapi-symfony-routing)

PHPackages © 2026

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