PHPackages                             malek/laravel-api-versioning - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. malek/laravel-api-versioning

ActiveLibrary[API Development](/categories/api)

malek/laravel-api-versioning
============================

Opinionated API versioning, deprecation lifecycle, usage tracking and alerts for Laravel

v1.0.0(4mo ago)10MITPHPPHP ^8.1CI failing

Since Feb 11Pushed 4mo agoCompare

[ Source](https://github.com/malek-deghlawi/laravel-api-versioning)[ Packagist](https://packagist.org/packages/malek/laravel-api-versioning)[ RSS](/packages/malek-laravel-api-versioning/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Laravel API Versioning &amp; Deprecation Manager
================================================

[](#laravel-api-versioning--deprecation-manager)

[![Latest Version](https://camo.githubusercontent.com/ae439d093a068a30d1fd380498840a2847f36d5d3562fcfa163fdf945cff88b0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6d616c656b2d646567686c6177692f6c61726176656c2d6170692d76657273696f6e696e67)](https://github.com/malek-deghlawi/laravel-api-versioning/releases)[![License](https://camo.githubusercontent.com/f1c4ddcb845116fba1f04af4bf4ab127d2ace03ff19f5c5dc021f86b6afd27b0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d616c656b2d646567686c6177692f6c61726176656c2d6170692d76657273696f6e696e67)](LICENSE)[![PHP Version](https://camo.githubusercontent.com/351755b1ea3b8a079461d461cd8142582eb91df14fea214307a660632576b07a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e312532422d626c7565)](#requirements)[![Laravel](https://camo.githubusercontent.com/eb63e0ada4a0b339ddd531a44590d209b504e9f4961e3f5ef99c2e169c4e4381/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d313025323025374325323031312d726564)](#requirements)

A production-ready **API Versioning &amp; Deprecation Lifecycle Manager for Laravel**.

---

Table of Contents
-----------------

[](#table-of-contents)

- [Why This Package?](#why-this-package)
- [Features](#features)
- [Installation](#installation)
- [Quick Example](#quick-example)
- [Configuration](#configuration)
- [Architecture](#architecture)
- [Artisan Commands](#artisan-commands)
- [Use Cases](#use-cases)
- [Production Notes](#production-notes)
- [Testing](#testing)
- [Roadmap](#roadmap)
- [Contributing](#contributing)
- [License](#license)
- [Author](#author)

---

Why This Package?
-----------------

[](#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
--------

[](#features)

### API Versioning

[](#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

[](#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

[](#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

[](#deprecated-usage-alerts)

- Configurable threshold
- Time window monitoring
- Critical log trigger

Installation
------------

[](#installation)

### Requirements

[](#requirements)

- PHP 8.1+
- Laravel 10 or 11

#### Install:

[](#install)

```
composer require malek/laravel-api-versioning
```

#### Publish config:

[](#publish-config)

```
php artisan vendor:publish --tag=api-versioning-config
```

Quick Example
-------------

[](#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
-------------

[](#configuration)

### File:

[](#file)

```
config/api-versioning.php

```

### Default Version

[](#default-version)

```
'default_version' => 'v1',

```

### Version Resolver

[](#version-resolver)

```
'resolver' => [
    'header' => 'X-API-Version',
    'query'  => 'api_version',
],

```

### Client Resolver

[](#client-resolver)

```
'client' => [
    'resolver' => 'header',
    'header'   => 'X-API-KEY',
    'fallback' => 'anonymous',
],

```

### Usage Tracking

[](#usage-tracking)

```
'usage' => [
    'enabled' => true,
    'ttl' => 60 * 60 * 24 * 30,
],

```

### Deprecation Alerts

[](#deprecation-alerts)

```
'alerts' => [
    'enabled' => true,
    'threshold' => 100,
    'window_minutes' => 5,
],

```

Architecture
------------

[](#architecture)

```
Request
  ↓
ResolveApiVersion Middleware
  ↓
VersionedRouteRegistrar
  ↓
DeprecationHeaders Middleware
  ↓
ApiUsageTracker
  ↓
DeprecatedUsageMonitor
  ↓
Response

```

Artisan Commands
----------------

[](#artisan-commands)

```
php artisan api:versions
php artisan api:deprecated
php artisan api:usage
php artisan api:alerts

```

Use Cases
---------

[](#use-cases)

- Mobile API version governance
- SaaS public APIs
- Gradual API migrations
- Enterprise API lifecycle control
- B2B multi-client APIs

Production Notes
----------------

[](#production-notes)

- Uses Laravel Cache (Redis recommended)
- Logging-based alert mechanism
- No database dependency
- Horizontal scaling friendly

Testing
-------

[](#testing)

```
vendor/bin/phpunit

```

Roadmap
-------

[](#roadmap)

- Database persistence driver
- Slack / email alert integration
- Prometheus metrics exporter
- OpenAPI compatibility
- Sunset enforcement mode

Admin dashboard

Contributing
------------

[](#contributing)

- Fork repository
- Create feature branch
- Submit Pull Request

License
-------

[](#license)

MIT License

Author
------

[](#author)

Malek Deghlawi
 GitHub:

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance74

Regular maintenance activity

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

143d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f2627c8dd572f3f58c96e46a5ea3dad4ec9fb40fbc5f17397b536683d77bd16a?d=identicon)[malek-deghlawi](/maintainers/malek-deghlawi)

---

Top Contributors

[![malek-deghlawi](https://avatars.githubusercontent.com/u/42089338?v=4)](https://github.com/malek-deghlawi "malek-deghlawi (4 commits)")

---

Tags

api-deprecationapi-versioninglaravellaravel-packagelaravel-packagesphprest-apilaravellaravel-packageREST APIapi versioningapi-deprecation

### Embed Badge

![Health badge](/badges/malek-laravel-api-versioning/health.svg)

```
[![Health](https://phpackages.com/badges/malek-laravel-api-versioning/health.svg)](https://phpackages.com/packages/malek-laravel-api-versioning)
```

###  Alternatives

[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816333.8k3](/packages/defstudio-telegraph)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5021.9k](/packages/simplestats-io-laravel-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
