1. Go to this page and download the library: Download mateodioev/http-router library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mateodioev / http-router example snippets
use Mateodioev\HttpRouter\exceptions\{HttpNotFoundException, RequestException};
use Mateodioev\HttpRouter\{Request, Response, Router};
$router = new Router();
// Register your endpoints here
$router->get('/', function (Request $r) {
return Response::text('Hello world!');
});
$router->run();
$router->myHttpMethod($uri, $callback);
$router->static($baseUri, $path, $methods);
// Default methods are GET
$router->static('/docs', 'public/');
$router->all($uri, $callback);
$router->get('/page/{name}', function (Request $r) {
return Response::text('Welcome to ' . $r->param('name'));
});
$router->get('/page/{name}?', function (Request $r) {
$pageName = $r->param('name') ?? 'home'; // If the parameter is not present, the method return null
return Response::text('Welcome to ' . $pageName);
});
text
.
├── index.php
└── styles.css
1 directory, 2 files
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.