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

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

viragrajput/router
==================

A custom router package for handling HTTP routing in PHP applications

v1.0.2(2y ago)08MITPHP

Since May 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ViragRajput/Router)[ Packagist](https://packagist.org/packages/viragrajput/router)[ RSS](/packages/viragrajput-router/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (4)Used By (0)

Virag Router
============

[](#virag-router)

ViragRouter is a lightweight PHP router package that allows you to easily define and handle routes in your PHP applications.

With ViragRouter, you're equipped with a robust suite of capabilities essential for efficient route handling: seamless route definition, dynamic parameter management, route grouping with middleware support, named routes for URL generation, and more. Its lightweight architecture guarantees minimal overhead, delivering optimal performance without sacrificing functionality.

Note :
------

[](#note-)

ViragRouter is actively developed and continuously enhanced. While it's currently in its developmental phase and may contain occasional bugs, so it is not recommended for production use at this time. We appreciate your patience and understanding as i work towards delivering a stable and reliable product. However, you can safely use it for learning purposes, exploring its features, and exploring advanced routing concepts in PHP.

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

[](#installation)

You can install ViragRouter via Composer:

```
composer require viragrajput/router
```

Run local PHP Server
--------------------

[](#run-local-php-server)

```
php -S localhost:8000 -t public

```

Usage
-----

[](#usage)

### Creating Routes

[](#creating-routes)

You can define routes using the `Route` class provided by ViragRouter. Here's an example of how to define a route:

```
use Virag\Router\Route;

Route::get('/hello', function () {
    echo "Hello, World!";
});

Route::get('/hello', [HelloController::class, 'index']);
```

### Route Parameters

[](#route-parameters)

You can define route parameters by enclosing them in curly braces `{}`. These parameters will be passed to your route handler. Here's an example:

```
use Virag\Router\Route;

Route::get('/users/{id}', function ($id) {
    echo "User ID: $id";
});

Route::get('/users/{id}', [UserController::class, 'show']);
```

### Route Groups

[](#route-groups)

You can group routes and apply common attributes using the `group` method. Here's an example:

```
use Virag\Router\Route;

Route::group(['middleware' => 'auth'], function () {
    Route::get('/dashboard', 'DashboardController@index');
    Route::get('/settings', 'SettingsController@index');
});

Route::group(['middleware' => 'auth'], function () {
    Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
    Route::get('/settings', [SettingsController::class, 'index'])->name('settings');
});
```

### Named Routes

[](#named-routes)

You can name your routes using the `name` method. Named routes allow you to generate URLs based on the route name. Here's an example:

```
use Virag\Router\Route;

Route::get('/profile', 'ProfileController@index')->name('profile');

Route::get('/profile', [ProfileController::class, 'index'])->name('profile');
```

### Middleware

[](#middleware)

You can apply middleware to routes using the `middleware` method. Middleware allows you to filter HTTP requests entering your application. Here's an example:

```
use Virag\Router\Route;

Route::get('/admin', 'AdminController@index')->middleware('admin');

Route::get('/admin', [AdminController::class, 'index'])->middleware('admin');
```

### Generating URLs

[](#generating-urls)

You can generate URLs for named routes using the `generateUrl` method. Here's an example:

```
use Virag\Router\Route;

$url = Route::generateUrl('profile');
echo "Profile URL: $url";
```

### Handling Requests

[](#handling-requests)

You can handle incoming requests using the dispatch method of the Router class. Here's an example:

```
use Virag\HttpFoundation\Request;
use Virag\HttpFoundation\Response;

$router = new Router();

$request = Request::createFromGlobals();
$response = $router->dispatch($request);
$response->send();
```

How To Use This Package in Your Custom PHP Project
--------------------------------------------------

[](#how-to-use-this-package-in-your-custom-php-project)

Certainly! Below is an example of how you can integrate the ViragRouter package into your custom PHP Project:

### Step 1: Install ViragRouter via Composer

[](#step-1-install-viragrouter-via-composer)

First, install the ViragRouter package via Composer:

```
composer require viragrajput/router
```

### Step 2: Define Routes in Your Custom Project

[](#step-2-define-routes-in-your-custom-project)

In your custom Project, you'll need to define routes using the ViragRouter `Route` class. Here's an example of how you can define routes in your Project:

```
// index.php

require_once 'vendor/autoload.php';

use ViragRouter\Route;

Route::get('/', function () {
    echo "Welcome to my custom Project!";
});

Route::get('/hello/{name}', function ($name) {
    echo "Hello, $name!";
});
```

### Step 3: Create a Router Instance and Handle Requests

[](#step-3-create-a-router-instance-and-handle-requests)

In your Project entry point (e.g., `index.php`), create a router instance and handle incoming requests:

```
// index.php

require_once 'vendor/autoload.php';

use ViragRouter\Router;
use Virag\HttpFoundation\Request;
use Virag\HttpFoundation\Response;

$router = new Router();

$request = Request::createFromGlobals();
$response = $router->dispatch($request);
$response->send();
```

### Step 4: Handle Requests in Your Custom Project

[](#step-4-handle-requests-in-your-custom-project)

In your custom Project, ensure that you have logic to handle requests and invoke the appropriate route handlers based on the incoming requests.

### Step 6: Additional Configuration (Optional)

[](#step-6-additional-configuration-optional)

Depending on your custom Project's architecture and requirements, you may need to configure additional features such as middleware, route groups, named routes, etc., provided by ViragRouter.

By following these steps, you should be able to integrate the ViragRouter package into your custom PHP project and define and handle routes effectively. Adjustments may be needed based on your project's specific requirements and architecture.

License
-------

[](#license)

This package is open-source software licensed under the [MIT license](LICENSE).

---

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

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

Total

3

Last Release

741d ago

### Community

Maintainers

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

---

Top Contributors

[![ViragRajput](https://avatars.githubusercontent.com/u/108286928?v=4)](https://github.com/ViragRajput "ViragRajput (12 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

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