https://github.com/thiiagoms/trouter
:elephant: :arrows_counterclockwise: TRouter is a lightweight and flexible PHP router library designed for building web applications and APIs
https://github.com/thiiagoms/trouter
php php-router php-routing router
Last synced: over 1 year ago
JSON representation
:elephant: :arrows_counterclockwise: TRouter is a lightweight and flexible PHP router library designed for building web applications and APIs
- Host: GitHub
- URL: https://github.com/thiiagoms/trouter
- Owner: thiiagoms
- License: 0bsd
- Created: 2023-01-19T10:49:45.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-08T13:39:07.000Z (about 2 years ago)
- Last Synced: 2025-01-16T09:07:54.028Z (over 1 year ago)
- Topics: php, php-router, php-routing, router
- Language: PHP
- Homepage:
- Size: 109 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
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 :memo:
- Docker or Composer (PHP8.1+)
### Install :package:
#### Composer
```bash
$ composer require thiiagoms/trouter
```
#### Docker
01 - Clone the repository:
```bash
$ git clone https://github.com/thiiagoms/trouter
```
02 - Switch to `trouter` directory:
```bash
$ cd trouter
trouter $
```
03 - Run `setup.sh`:
```bash
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 :gear:
Here's a basic example of how to use TRouter to define and handle routes in your PHP application:
```php
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();
```