PHPackages                             liamrabe/basic-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. liamrabe/basic-router

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

liamrabe/basic-router
=====================

A basic router

v2.1.2(3y ago)0371MITPHP

Since Sep 12Pushed 3y ago1 watchersCompare

[ Source](https://github.com/liamrabe/BasicRouter)[ Packagist](https://packagist.org/packages/liamrabe/basic-router)[ RSS](/packages/liamrabe-basic-router/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)DependenciesVersions (9)Used By (0)

BasicRouter
===========

[](#basicrouter)

A basic router

Basic Install
-------------

[](#basic-install)

```
composer require liamrabe/basic-router
```

Basic usage
-----------

[](#basic-usage)

```
use LiamRabe\BasicRouter\Middleware\AbstractMiddleware;
use LiamRabe\BasicRouter\Controller\AbstractErrorController;
use LiamRabe\BasicRouter\DataCollection\Response;
use LiamRabe\BasicRouter\DataCollection\Request;
use LiamRabe\BasicRouter as Router;

class APIMiddleware {

	public static function handle() {
		return true;
	}

}

class AppMiddleware {

	public static function handle() {
		return true;
	}

}

function handleRoute(Request $request, Response $response): Response {
	$response->setHeader('Content-Type', 'text/html');
	$response->setBody('Hello, world!');
	$response->setStatus(200);

	return $response;
}

try {

	/** setErrorController & setMiddleware are required before adding routes */
	Router::setErrorController(ErrorController::class, 'handleError');
	Router::setMiddleware(AppMiddleware::class, 'handleRequest');

	Router::redirect('/', '/home');

	Router::get('/home', 'handleRoute');

	Router::put('/home', 'handleRoute');

	Router::post('/home', 'handleRoute');

	Router::delete('/home', 'handleRoute');

	Router::all('/home', 'handleRoute');

	Route::group('/api', static function() {
		/** Added route will have URI '/api/v1/customer' */
		Route::get('/v1/customers', 'handleRoute');
	}, [APIMiddleware::class, 'handleRequest']);

	Router::run();

} catch (Exception $ex) {
	echo $ex->getMessage();
}
```

Basic Documentation
-------------------

[](#basic-documentation)

BasicRouter supports `GET`, `PUT`, `POST` and `DELETE`

### Basic HTTP Methods

[](#basic-http-methods)

**All**

```
/** Use this if you want to register a route on all HTTP methods */
Router::all('/', [AbstractController::class, 'handleRoute']);
```

**GET**

```
Router::get('/', [AbstractController::class, 'handleRoute']);
```

**PUT**

```
Router::put('/', [AbstractController::class, 'handleRoute']);
```

**POST**

```
Router::post('/', [AbstractController::class, 'handleRoute']);
```

**DELETE**

```
Router::delete('/', [AbstractController::class, 'handleRoute']);
```

### Basic General methods

[](#basic-general-methods)

**Redirect**

```
/** Redirect route '/' to '/home' with response code 301 */
Router::redirect('/', '/home', 301);
```

### Regex URI

[](#regex-uri)

You can define regex directly on the URI

**Format**: `{[PARAMETER_NAME]:[REGEX_PATTERN]}`

**Example**:

```
/** Regex on route doesn't need parenthesis will be applied at runtime */
Router::get('/api/customers/{customer_id:[a-zA-Z0-9]+}', 'handleRoute');
```

FunctionReturnsRouter::**getMethod**()string - `$_SERVER['REQUEST_METHOD']`Router::**getUri**()string - `$_SERVER['REQUEST_URI']`Router::**getSemVer**()string - `1.0.0`Router::**getMajor**()int - `1`Router::**getMinor**()int - `0`Router::**getPatch**()int - `0`

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity52

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

Total

7

Last Release

1337d ago

Major Versions

v1.0.0 → v2.0.02022-09-14

v2.1.2 → v3.0.0.x-dev2022-09-20

### Community

Maintainers

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

---

Top Contributors

[![liamrabe](https://avatars.githubusercontent.com/u/28879732?v=4)](https://github.com/liamrabe "liamrabe (19 commits)")

### Embed Badge

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

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

PHPackages © 2026

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