Skip to content

tahashieenavaz/router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minimal PHP Request Router

Every professional web developer knows handling request routing can be a pain in the ***. I sometimes wished there could be an excessively lightweight library which handles request routing. So I wasn't forced to load Laravel or even Lumen to do so. This repository contains my solution for my own problem but I think others will find it useful too.

Installation

composer require underdash/router

Using Closures

use Underdash\Router;

Router::get('/', function() {
  return "Welcome to my blog!";
});

Router::dispatch();

Using Controllers

use Underdash\Router;

class PagesController {
    public static function index(){
        return "Welcome from controller!";
    }
}

Router::get('/', 'PagesController@index');

Router::dispatch();

Minimal Wildcard Support

use Underdash\Router;

Router::get('/user/{name}', function($name) {
  return "You are probably {$name}, and I know it!";
});

Router::dispatch();

Working with POST params made easy

use Underdash\Router;

Router::post('register', function() {
  $name = arg('name');
  return "Thanks for registering in our web service, {$name}";
});

Router::dispatch();

About

Minimal PHP request router, designed with simplicity and ease of use in mind.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages