PHP code example of mnarbash / api-versioning-by-header-request
1. Go to this page and download the library: Download mnarbash/api-versioning-by-header-request 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/ */
mnarbash / api-versioning-by-header-request example snippets
Mnarbash\ApiVersioningByHeaderRequest\ApiVerServiceProvider::class,
Route::get('testVer', ApiVersioning::UseApiMultiVersions([
'V1' => [V1TestApiController::class, 'testVer'],
'V0' => [TestApiController::class, 'testVer'],
'0' => [TestApiController::class, 'testVer'] //set default version if not set in header
]))
Route::prefix('test')->group( function () {
Route::get('func', ApiVersioning::UseApiMultiVersions(
[
'0'=> function () {
return 'version 0 or default version';
},
'V1' => function () {
return 'v1';
},
'V2' => function () {
return 'v2';
},
'V3' => function () {
return 'v3';
},
'V5' => function () {
return 'v5';
},
]
));
Route::get('controller', ApiVersioning::UseApiMultiVersions(
[
'0'=> [V0TestController::class, 'index'],
'V1' => [V1TestController::class, 'index'],
'V2' => [V2TestController::class, 'index'],
'V3' => [V3TestController::class, 'index'],
'V5' => [V5TestController::class, 'index'],
]
));
Route::resource('res', ApiVersioning::UseApiMultiVersions(
[
'0'=> ResourceController::class,
'V2'=> V2ResourceController::class,
]
));
});
$apiVersion = ApiVersioning::getApiVersion();
use Mnarbash\ApiVersioningByHeaderRequest\Middleware\CheckAppVersion;
protected $middlewareGroups = [
'api' => [
// ...
CheckAppVersion::class,
],
];
sh
php artisan vendor:publish --provider="Mnarbash\ApiVersioningByHeaderRequest\ApiVerServiceProvider" --tag=config