Skip to content

lgrdev/SimpleRouter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleRouter

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']);

About

A very simple router

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages