PHP code example of vogon101 / dynamic-endpoints

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

    

vogon101 / dynamic-endpoints example snippets




 composer 

$base = "/dynamic-endpoints/test";
$API = new BluePost\API($base);

//Register the endpoints
//Variables are defined with %varName
//A .. is a wildcard
$API->register(Array(
    "/api/movie/../%name/%prop/.." => __DIR__ . "/movie.php",
    "/api/movie/" => __DIR__ . "/movie2.php",
    "/api/book/%id" => __DIR__ . "/book.php",
    "/api/book/name/%name" => __DIR__ . "/book2.php"
));

//Look for an endpoint, will run the file if one is found
$result = $API->runEndpoint();
if (array_key_exists("error", $result)) var_dump ($result);

ErrorDocument 404 /dynamic-endpoints/test/index.php