https://github.com/esase/tiny-router
Standalone routing implementation for HTTP and console requests
https://github.com/esase/tiny-router
esase framework lightweight microservices mvc routing tinyframework
Last synced: 13 days ago
JSON representation
Standalone routing implementation for HTTP and console requests
- Host: GitHub
- URL: https://github.com/esase/tiny-router
- Owner: esase
- License: mit
- Created: 2020-07-28T06:50:27.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-04-19T19:45:46.000Z (almost 3 years ago)
- Last Synced: 2025-11-27T14:56:12.069Z (about 2 months ago)
- Topics: esase, framework, lightweight, microservices, mvc, routing, tinyframework
- Language: PHP
- Homepage:
- Size: 67.4 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tiny-router
[](https://travis-ci.com/github/esase/tiny-router/builds)
[](https://coveralls.io/github/esase/tiny-router?branch=master)
**Tiny/Routing** - it's a layer between the outside world like a browser or a console command [CLI](https://en.wikipedia.org/wiki/Command-line_interface)
and your application. The package may be integrated to any existing `php` project and it does not require any
extra packages.
**Usually routing contains of two main parts:**
1. `Routes` - which describe a meta information like - a `query`, a query `type`, and
a responsible `controller` which processes all incoming requests.
2. A `Router` - just holds registered routes and matches incoming requests with registered routes.
So it just returns either a matched route or trigger an `Exception` when a route is not found.
Current implementation of routing is very simple but in the same time very powerful. It gets you
a possibility to work with it using a plain requests (`literal`) and [Regexp](https://en.wikipedia.org/wiki/Regular_expression) based requests,
also it supports filtering requests by http requests types like: `GET`, `POST`, etc.
Also you can use it as a routing for you `CLI` projects.
**So let's check a look an http routing example:**
```php
// create an instance of the router
$router = new Router(new RequestHttpParams($_SERVER));
// a literal `home` route
$router->registerRoute(new Route(
'/',
'HomeController',
'index'
));
// a literal `users` route which accepts only `GET` and `POST` requests
$router->registerRoute(new Route(
'/users',
'UserController',
// list of actions
[
'GET' => 'list',
'POST' => 'create'
]
));
// a more complex example using a `RegExp` rule
$router->registerRoute(new Route(
'|^/users/(?P\d+)$|i', // it's matches to: `/users/1`, `/users/300`, etc
'UserController',
[
'GET' => 'view',
'DELETE' => 'delete',
],
'regexp',
['id']
));
// now get a matched route
$matchedRoutes = $router->getMatchedRoute();
```
## Installation
Run the following to install this library:
```bash
$ composer require esase/tiny-router
```
## Documentation
https://tiny-docs.readthedocs.io/en/latest/tiny-router/docs/index.html