lgrdev/simplerouter

A very simple php router

Installs: 16

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/lgrdev/simplerouter

1.0.1 2023-11-01 05:55 UTC

This package is auto-updated.

Last update: 2025-10-29 03:34:10 UTC


README

A very simple router for GET, POST, PUT, DELETE methods

Software License Latest Version

Install

$ composer require lgrdev/simplerouter

Usage

$myrouter = new SimpleRouter();

// add route to home page
$myrouter->addGet('/', function () {   echo 'Hello, I\'m the home page'; } );

// route with a parameter
$myrouter->addGet('/book/{id}', function ($id) {   echo 'Hello, book #' . $id; } );

// route with a parameter id with format control
$myrouter->addGet('/book/{id:[0-9a-f]+}', function ($id) {   echo 'Hello, book #' . $id; } );

// route with a parameter and an optional parameter id2
$myrouter->addGet('/user/{id1}/{?id2}', function ($id1, $id2 = null) {   echo 'Hello User ' . $id; } );

// add a route for the method DELETE
$myrouter->addDelete('/book/{id:[0-9a-f]+}',  function ($id) {   echo 'Delete book #' . $id; } );

// add a POST route
$myrouter->addPost('/book', function ($id) {   echo 'Post a new book #'; } );

// display page
$myrouter->run($_REQUEST['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);