Skip to content

🐘 🔄 TRouter is a lightweight and flexible PHP router library designed for building web applications and APIs

License

Notifications You must be signed in to change notification settings

thiiagoms/trouter

Repository files navigation

Logo

Vanilla PHP Router 🧙

PHP Shell Script Docker

TRouter is a lightweight and flexible routing library for PHP. It allows you to easily define and manage your application's routes in a clear and concise way, without requiring any external dependencies or complicated configuration.

With TRouter, you can quickly and easily define routes using a simple and intuitive syntax. You can specify the HTTP method, the path pattern, and a callback function that should be executed when the route is matched. You can also define optional parameters and regular expression constraints for your routes, making it easy to handle dynamic and complex URLs

Dependencies 📝

  • Docker or Composer (PHP8.1+)

Install 📦

Composer

$ composer require thiiagoms/trouter

Docker

01 - Clone the repository:

$ git clone https://github.com/thiiagoms/trouter

02 - Switch to trouter directory:

$ cd trouter
trouter $

03 - Run setup.sh:

trouter $ chmod +x ./setup.sh
trouter $ ./setup.sh

████████╗██████╗  ██████╗ ██╗   ██╗████████╗███████╗██████╗ 
╚══██╔══╝██╔══██╗██╔═══██╗██║   ██║╚══██╔══╝██╔════╝██╔══██╗
   ██║   ██████╔╝██║   ██║██║   ██║   ██║   █████╗  ██████╔╝
   ██║   ██╔══██╗██║   ██║██║   ██║   ██║   ██╔══╝  ██╔══██╗
   ██║   ██║  ██║╚██████╔╝╚██████╔╝   ██║   ███████╗██║  ██║
   ╚═╝   ╚═╝  ╚═╝ ╚═════╝  ╚═════╝    ╚═╝   ╚══════╝╚═╝  ╚═╝

  [*] Author: Thiago Silva AKA thiiagoms
  [*] E-mail: thiagom.devsec@gmail.com

04 - Go to http://localhost:8000

Usage ⚙️

Here's a basic example of how to use TRouter to define and handle routes in your PHP application:

<?php

require_once 'vendor/autoload.php';

use Trouter\Router;

$router = new Router();

$router->get('/', function () {
    echo 'Hello, world!';
});

$router->get('/posts', function () {
    echo 'List of posts';
});

$router->get('/posts/:id', function ($id) {
    echo "Showing post #$id";
});

$router->post('/posts', function () {
    echo 'Creating a new post';
});

$router->put('/posts/:id', function ($id) {
    echo "Updating post #$id";
});

$router->delete('/posts/:id', function ($id) {
    echo "Deleting post #$id";
});

$router->run();

About

🐘 🔄 TRouter is a lightweight and flexible PHP router library designed for building web applications and APIs

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published