Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/samfelgar/simple-router
https://github.com/samfelgar/simple-router
Last synced: 16 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/samfelgar/simple-router
- Owner: samfelgar
- Created: 2022-07-20T22:30:19.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-07-20T22:45:12.000Z (over 2 years ago)
- Last Synced: 2024-11-08T14:13:30.647Z (2 months ago)
- Language: PHP
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple Router
## Credit
Based on Programming With Gio awesome playlist, available [here](https://www.youtube.com/playlist?list=PLr3d3QYzkw2xabQRUpcZ_IBk9W50M9pe-).
## Disclaimer
This project is for educational purposes only, **DO NOT USE IT IN PRODUCTION**.
## Usage
To register your routes, use the `\Samfelgar\SimpleRouter\Router` register method.
There is also shorthand methods for each HTTP method.```php
use Samfelgar\SimpleRouter\Router;$router = new Router();
$router->register('get', '/', fn () => 'Hello World!');
$router->get('/bye', fn () => 'See you!');
```To resolve the routes, you may call the `\Samfelgar\SimpleRouter\Router::resolve` method.
```php
use Samfelgar\SimpleRouter\Router;$router = new Router();
$response = $router->resolve($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
```