underdash/router

The minimal router

1.1 2022-06-09 13:41 UTC

This package is auto-updated.

Last update: 2024-07-09 18:34:56 UTC


README

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();