PHP code example of funkybunch / simple-http-router
1. Go to this page and download the library: Download funkybunch/simple-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/ */
funkybunch / simple-http-router example snippets
$router = new FunkyBunch\SimpleHTTPRouter\Router;
$router->get($path, function(){});
/**
* HTTP Router for myWebApp
* @author You!
*/
$router = new FunkyBunch\SimpleHTTPRouter\Router;
$router->get('/', function() {
// The following code will be executed when this `route` is called.
echo "<h1>Hello world</h1>";
});
$router->get('/about', function() {
// The following code will be executed when this `route` is called.
echo "<h1>About Us</h1>";
});
$router->post($path, function(){});
/**
* HTTP Router for myWebApp
* @author You!
*/
$router = new FunkyBunch\SimpleHTTPRouter\Router;
$router->get('/', function() {
// The following code will be executed when this `route` is called.
echo "<h1>Hello world</h1>";
});
$router->get('/about', function() {
// The following code will be executed when this `route` is called.
echo "<h1>About Us</h1>";
});
$router->post('/api/contact', function() {
// The following code will be executed when this `route` is called.
// Handle `POST` data
});
$router->getRequest()
$router->post($path, function() use(&$router) {
$request = $router->getRequest();
// DO SOMETHING WITH $request
}
/**
* HTTP Router for myWebApp
* @author You!
*/
$router = new FunkyBunch\SimpleHTTPRouter\Router;
$router->get('/', function() {
// The following code will be executed when this `route` is called.
echo "<h1>Hello world</h1>";
});
$router->get('/about', function() {
// The following code will be executed when this `route` is called.
echo "<h1>About Us</h1>";
});
$router->post('/api/contact', function() use(&$router) {
// The following code will be executed when this `route` is called.
$request = $router->getRequest();
// DO SOMETHING WITH $request to read POST data
});
sh
src/
|- HTTPErrors.php
|- Request.php
|- Router.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.