api-tools/api-version-manager
Composer 安装命令:
composer require api-tools/api-version-manager
包简介
Simplify Laravel API versioning with ease. No more separate controllers—just flexibility, fallbacks, and version-specific components.
关键字:
README 文档
README
The Laravel API Version Manager Package streamlines the management of API endpoint versions in Laravel applications. This package empowers you to effortlessly handle API versioning, eliminating the necessity to create individual controllers for each version. Its design presents a flexible and efficient solution, enabling you to define fallback versions and effortlessly generate version-specific Requests and Resources.
Features
- Fallback Versions: Define fallback versions for your API routes, ensuring smooth transitions and maintaining backward compatibility.
- Single Controller: Eliminate the need to create separate controllers for each API version. Our package dynamically injects version-specific Request and Resource classes into your existing controller.
- Effortless Versioning: Easily manage API versions through route configuration. The package automatically handles the resolution of version-specific components, streamlining your development process.
Installation
You can install the package via Composer:
composer require api-tools/api-version-manager
Configuration
Publish Config File
It is mandatory to publish the config file before using the package. You can publish the config file using the following command:
php artisan vendor:publish --tag=api-version-manager
Mandatory Configurations:
- Define available
versionsarray in config - Define default version
versionin config
Other possible configurations are:
app_http_namespace(default:App\Http) - Generally we useApp\Httpnamespace to store all our requests & resources classes, but if you are using different namespace then you can define it here.api_prefix(default:api) - API prefix for all versioned routes.use_fallback_entity(default:true) - If you want to use fallback entity for all request & resource class then set this totrue, otherwise set it tofalse. For example, you defineSampleRequestin V1, and now you want to use same request in V2 then you can set this option totrueand it will automatically useSampleRequestfrom V1.
Available Commands
Create a new versioned request
php artisan make:versioned-request {name}
Possible options:
--force: Overwrite the request if it already exists.
Create a new versioned resource
php artisan make:versioned-resource {name}
Possible options:
--collection: Create a resource collection instead of a single resource.--force: Overwrite the resource if it already exists.
Usage
Example of api.php file:
Route::prefix('v1')->group(function () { Route::get('endpoint1', [SomeController::class, 'endpoint1']); // Available on v1 & v2 (Via default fallback) Route::get('endpoint2', [SomeController::class, 'endpoint2']); // Available on v1 & v2 (Via default fallback) }); Route::prefix('v2')->group(function () { Route::get('new-endpoint', [SomeController::class, 'endpoint3']); // Available only on v2 });
Example of SomeController.php file:
<?php namespace App\Http\Controllers\API; use App\Http\Controllers\Controller; use App\Http\Resources\Versioned\EndpointResource; // Mandatory to use versioned resource only. Don't use `App\Http\Resources\V1\EndpointResource` or `App\Http\Resources\V2\EndpointResource` use App\Http\Requests\Versioned\NewEndpointRequest; // Mandatory to use versioned request only. Don't use `App\Http\Requests\V1\NewEndpointRequest` or `App\Http\Requests\V2\NewEndpointRequest` use Illuminate\Http\Request; class SomeController extends Controller { public function endpoint1(Request $request) { return DashboardResource::item(['some' => 'data']); // Replacement of native `new DashboardResource(['some' => 'data'])` resource } public function endpoint1(Request $request) { return DashboardResource::collection(['some' => 'data']); } public function endpoint3(NewEndpointRequest $request) { return DashboardResource::item(['some' => 'data']); } }
License
The MIT License (MIT). Please see License File for more information.
api-tools/api-version-manager 适用场景与选型建议
api-tools/api-version-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.34k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 01 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「laravel-package」 「api-versioning」 「laravel-resource」 「api-version-manager」 「laravel-apis」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 api-tools/api-version-manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 api-tools/api-version-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 api-tools/api-version-manager 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Enable Api Versioning for Laravel
A Laravel package for converting English numbers into Bangla digits, Bangla words, Bangla month names, and Bangla money format with an easy-to-use API.
Laravel table comments loader (part of Diplodocker project)
Versioned Laravel APIs with OpenAPI 3.0 docs auto-generated from PHP docblocks — no annotations, no YAML — plus CRUD scaffolding and middleware cascades.
jitone-ai is a powerful FilamentPHP plugin that integrates AI-powered features directly into your Filament forms.
A PSR-7 compatible library for making CRUD API endpoints
统计信息
- 总下载量: 2.34k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-01-09