PHP code example of iambib / api-version-fallback

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

    

iambib / api-version-fallback example snippets


return [
    /**
     * Enable the fallback
     */
    'enable' => true,
    /**
     * Available api versions
     */

    'available_versions' => [
        'v1',
        'v2',
    ],
    /**
     * Set them in order you want the fallback to happen
     * Eg. If v4 is not found v3 is the first one to check if exists. If not, v2 then v1.
     */
    'api_fallbacks' => [
        'v3', 'v2', 'v1',
    ],
    /*
     * URL segment number of your api version
     */
    'segment_no' => 0,
];

	$app = new \iAmBiB\ApiVersionFallback\Extension\Application(
		$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
	);
 	...
   $app->middleware([
		...
		'api_versioning_fallback' => \iAmBiB\ApiVersionFallback\Middleware\ApiVersioningFallback::class,
	]);
	...
	$app->configure('api-versioning');