PHP code example of mnavarrocarter / amp-http-router
1. Go to this page and download the library: Download mnavarrocarter/amp-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/ */
mnavarrocarter / amp-http-router example snippets
declare(strict_types=1);
use Amp\Http\Server\Request;
use Amp\Http\Server\Response;
use MNC\Router\Router;
use MNC\Router\RoutingContext;
use function MNC\Router\handleFunc;
use function MNC\Router\html;
use function MNC\Router\listenAndServe;
function homepage(): Response {
return html('Hello world!');
}
function findUser(Request $request): Response {
$id = RoutingContext::of($request)->getParam('id');
return html(sprintf('The user id is %s', $id));
}
$router = Router::create();
$router->get('/', handleFunc('homepage'));
$router->get('/users/:id', handleFunc('findUser'));
Amp\Loop::run(fn() => yield listenAndServe('0.0.0.0:8000', $router));
use MNC\Router\Router;
$app = Router::create();
// Define main app routes
$api = Router::create();
// Define api routes
// Api routes will be under `/api`
$app->mount('/api', $api);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.