PHP code example of meraki / http-router

1. Go to this page and download the library: Download meraki/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/ */

    

meraki / http-router example snippets



Meraki\Http\AutoRouter;
use Laminas\Diactoros\ServerRequestFactory;

$router = new AutoRouter('Project\\Http\\');
$request = ServerRequestFactory::fromGlobals();

$result = $router->route($request);

switch ($result->status) {
	case 200:
		// get the matched route
		$route = $result->route;

		// access info about the matching route
		$requestHandler = $route->requestHandler;
		$invokeMethod = $route->invokeMethod;
		$params = $route->parameters;
		break;

	case 404:
		// the request that couldn't be matched
		$request = $result->request;
		default;

	case 405:
		// fully qualified class name that was built
		$allowedMethods = $result->allowedMethods;
		default;

	default:
		// 500 internal server error
}

$parentResource = Project\Http\Contact\PostAction::class;
$childResource = Project\Http\Contact\Ping\PostAction::class;
text
POST /contact/0412345678/ping