malek/laravel-api-versioning
Composer 安装命令:
composer require malek/laravel-api-versioning
包简介
Opinionated API versioning, deprecation lifecycle, usage tracking and alerts for Laravel
README 文档
README
A production-ready API Versioning & Deprecation Lifecycle Manager for Laravel.
Table of Contents
- Why This Package?
- Features
- Installation
- Quick Example
- Configuration
- Architecture
- Artisan Commands
- Use Cases
- Production Notes
- Testing
- Roadmap
- Contributing
- License
- Author
Why This Package?
Laravel does not provide structured API lifecycle management out of the box.
As APIs evolve, teams need:
- Version isolation (
/v1,/v2) - Safe deprecation workflows
- Sunset communication
- Client-aware usage tracking
- Deprecated traffic monitoring
This package provides an opinionated and production-focused solution.
Features
API Versioning
- Route prefix versioning
- Header-based version resolution
- Query parameter fallback
- Version mismatch protection
Example:
use Malek\ApiVersioning\Facades\ApiRoute; ApiRoute::version('v1')->group(function () { Route::get('/users', fn () => 'Users v1'); });
Access:
GET /v1/users
API Deprecation Management
Mark routes as deprecated:
ApiRoute::version('v2') ->deprecated('2026-01-01', 'Please migrate to v3') ->group(function () { Route::get('/legacy', fn () => 'Deprecated'); });
Response headers:
Deprecation: true
Sunset: 2026-01-01
Warning: 299 - "Please migrate to v3"
Per-Client Usage Tracking
Tracks:
- Version
- Route
- Client (API key or authenticated user)
Supports:
- Header-based client resolution
- Auth-based resolution
- Anonymous fallback
Deprecated Usage Alerts
-
Configurable threshold
-
Time window monitoring
-
Critical log trigger
Installation
Requirements
- PHP 8.1+
- Laravel 10 or 11
Install:
composer require malek/laravel-api-versioning
Publish config:
php artisan vendor:publish --tag=api-versioning-config
Quick Example
use Malek\ApiVersioning\Facades\ApiRoute; ApiRoute::version('v1')->group(function () { Route::get('/users', fn () => 'Users v1'); }); ApiRoute::version('v2') ->deprecated('2026-01-01', 'Upgrade to v3') ->group(function () { Route::get('/users', fn () => 'Users v2'); });
Configuration
File:
config/api-versioning.php
Default Version
'default_version' => 'v1',
Version Resolver
'resolver' => [
'header' => 'X-API-Version',
'query' => 'api_version',
],
Client Resolver
'client' => [
'resolver' => 'header',
'header' => 'X-API-KEY',
'fallback' => 'anonymous',
],
Usage Tracking
'usage' => [
'enabled' => true,
'ttl' => 60 * 60 * 24 * 30,
],
Deprecation Alerts
'alerts' => [
'enabled' => true,
'threshold' => 100,
'window_minutes' => 5,
],
Architecture
Request
↓
ResolveApiVersion Middleware
↓
VersionedRouteRegistrar
↓
DeprecationHeaders Middleware
↓
ApiUsageTracker
↓
DeprecatedUsageMonitor
↓
Response
Artisan Commands
php artisan api:versions
php artisan api:deprecated
php artisan api:usage
php artisan api:alerts
Use Cases
- Mobile API version governance
- SaaS public APIs
- Gradual API migrations
- Enterprise API lifecycle control
- B2B multi-client APIs
Production Notes
-
Uses Laravel Cache (Redis recommended)
-
Logging-based alert mechanism
-
No database dependency
-
Horizontal scaling friendly
Testing
vendor/bin/phpunit
Roadmap
- Database persistence driver
- Slack / email alert integration
- Prometheus metrics exporter
- OpenAPI compatibility
- Sunset enforcement mode
Admin dashboard
Contributing
- Fork repository
- Create feature branch
- Submit Pull Request
License
MIT License
Author
Malek Deghlawi
GitHub: https://github.com/malek-deghlawi
malek/laravel-api-versioning 适用场景与选型建议
malek/laravel-api-versioning 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 02 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「rest-api」 「laravel-package」 「api-versioning」 「api-deprecation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 malek/laravel-api-versioning 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 malek/laravel-api-versioning 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 malek/laravel-api-versioning 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
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.
Provided middleware for generating of swagger-documentation file by run testing of restful API.
Laravel table comments loader (part of Diplodocker project)
jitone-ai is a powerful FilamentPHP plugin that integrates AI-powered features directly into your Filament forms.
A lightweight, secure-by-default PHP microframework built on Slim – providing Laravel-like features (ORM, authentication, migrations, caching) without the bloat. Perfect for building REST APIs and small-to-medium PHP applications.
Laravel JWT auth service package
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 32
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-11