PHPackages                             grazulex/laravel-apiroute - 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. grazulex/laravel-apiroute

ActiveLibrary[API Development](/categories/api)

grazulex/laravel-apiroute
=========================

Complete API versioning lifecycle management for Laravel

v2.0.5(3mo ago)1036.0k—3.7%3[1 issues](https://github.com/Grazulex/laravel-apiroute/issues)MITPHPPHP ^8.3CI passing

Since Dec 23Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/Grazulex/laravel-apiroute)[ Packagist](https://packagist.org/packages/grazulex/laravel-apiroute)[ Docs](https://github.com/grazulex/laravel-apiroute)[ Fund](https://paypal.me/strauven)[ GitHub Sponsors](https://github.com/Grazulex)[ RSS](/packages/grazulex-laravel-apiroute/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (12)Versions (13)Used By (0)

Laravel ApiRoute
================

[](#laravel-apiroute)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5c1c3366a05cbce0fa86b610917b2e303326ab658dbf30f33af7f1b07e664619/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6772617a756c65782f6c61726176656c2d617069726f7574652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/grazulex/laravel-apiroute)[![Tests](https://github.com/grazulex/laravel-apiroute/actions/workflows/tests.yml/badge.svg)](https://github.com/grazulex/laravel-apiroute/actions/workflows/tests.yml)[![Static Analysis](https://github.com/grazulex/laravel-apiroute/actions/workflows/static-analysis.yml/badge.svg)](https://github.com/grazulex/laravel-apiroute/actions/workflows/static-analysis.yml)[![Code Style](https://github.com/grazulex/laravel-apiroute/actions/workflows/code-style.yml/badge.svg)](https://github.com/grazulex/laravel-apiroute/actions/workflows/code-style.yml)[![Total Downloads](https://camo.githubusercontent.com/580561cfe739d521ecedc9984931b740ae4c9c7f241201a8ddf87d5915a02fb4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6772617a756c65782f6c61726176656c2d617069726f7574652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/grazulex/laravel-apiroute)[![License](https://camo.githubusercontent.com/e45fb371d5844519ca78d4827c1d1901d56afd14cfde82e95f28b4070f41990a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6772617a756c65782f6c61726176656c2d617069726f7574652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/grazulex/laravel-apiroute)

> Complete API versioning lifecycle management for Laravel

Features
--------

[](#features)

- **Multi-strategy versioning** - URI path, Header, Query parameter, or Accept header
- **Automatic deprecation headers** - RFC 8594 (Deprecation) and RFC 7231 (Sunset) compliant
- **Version lifecycle management** - Active, Deprecated, Sunset, Removed states
- **Intelligent fallback** - Route fallback to previous versions when needed
- **Artisan commands** - Scaffold, monitor, and manage API versions
- **Usage tracking** - Optional analytics per API version
- **Zero configuration start** - Works out of the box with sensible defaults

Requirements
------------

[](#requirements)

- PHP 8.3+
- Laravel 12.x or 13.x

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

[](#installation)

```
composer require grazulex/laravel-apiroute
```

Publish the configuration file:

```
php artisan vendor:publish --tag="apiroute-config"
```

Documentation
-------------

[](#documentation)

For complete documentation including migrations, advanced configuration, and usage tracking setup, please visit the **[Wiki](https://github.com/Grazulex/laravel-apiroute/wiki)**.

Quick Start
-----------

[](#quick-start)

### 1. Define versions in config

[](#1-define-versions-in-config)

```
// config/apiroute.php

'versions' => [
    'v1' => [
        'routes' => base_path('routes/api/v1.php'),
        'status' => 'deprecated',
        'deprecated_at' => '2025-06-01',
        'sunset_at' => '2025-12-01',
        'successor' => 'v2',
    ],
    'v2' => [
        'routes' => base_path('routes/api/v2.php'),
        'status' => 'active',
    ],
    'v3' => [
        'routes' => base_path('routes/api/v3.php'),
        'status' => 'beta',
    ],
],
```

### 2. Create route files

[](#2-create-route-files)

```
// routes/api/v2.php
use Illuminate\Support\Facades\Route;

Route::apiResource('users', App\Http\Controllers\Api\V2\UserController::class);
```

Versioning Strategies
---------------------

[](#versioning-strategies)

### URI Path (Default)

[](#uri-path-default)

```
GET /api/v1/users
GET /api/v2/users

```

### Header

[](#header)

```
GET /api/users
X-API-Version: 2

```

### Query Parameter

[](#query-parameter)

```
GET /api/users?api_version=2

```

### Accept Header

[](#accept-header)

```
GET /api/users
Accept: application/vnd.api.v2+json

```

### Subdomain Routing

[](#subdomain-routing)

For APIs served from a dedicated subdomain:

```
// config/apiroute.php
'strategies' => [
    'uri' => [
        'prefix' => '',                    // No /api prefix
        'domain' => 'api.example.com',     // Your API subdomain
    ],
],
```

```
GET https://api.example.com/v1/users
GET https://api.example.com/v2/users

```

### Multi-Domain Routing

[](#multi-domain-routing)

For resilience or redundancy scenarios where the same API is served on multiple domains:

```
// config/apiroute.php
'strategies' => [
    'uri' => [
        'prefix' => '',
        'domain' => ['api.main.com', 'api.backup.com', 'api.proxy.com'],
    ],
],
```

All domains resolve to the same versioned routes:

```
GET https://api.main.com/v1/users
GET https://api.backup.com/v1/users
GET https://api.proxy.com/v1/users

```

Use environment variables for flexible configuration:

```
'domain' => array_filter(array_map('trim', explode(',', env('API_DOMAINS', '')))),
```

```
# .env
API_DOMAINS=api.main.com,api.backup.com,api.proxy.com
```

Automatic Headers
-----------------

[](#automatic-headers)

On deprecated versions, responses include RFC-compliant headers:

```
HTTP/1.1 200 OK
Deprecation: Sun, 01 Jun 2025 00:00:00 GMT
Sunset: Mon, 01 Dec 2025 00:00:00 GMT
Link: ; rel="successor-version"
X-API-Version: v1
X-API-Version-Status: deprecated
```

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

[](#artisan-commands)

```
# View status of all API versions
php artisan api:status

# Create a new API version
php artisan api:version v3 --copy-from=v2

# Mark a version as deprecated
php artisan api:deprecate v1 --on=2025-06-01 --sunset=2025-12-01

# View usage statistics
php artisan api:stats --period=30
```

Configuration
-------------

[](#configuration)

```
// config/apiroute.php

return [
    // API versions (v2.0+)
    'versions' => [
        'v1' => [
            'routes' => base_path('routes/api/v1.php'),
            'middleware' => [],
            'status' => 'active',  // 'active', 'beta', 'deprecated', 'sunset'
            'deprecated_at' => null,
            'sunset_at' => null,
            'successor' => null,
            'documentation' => null,
            'rate_limit' => null,
        ],
    ],

    // Detection strategy: 'uri', 'header', 'query', 'accept'
    'strategy' => 'uri',

    // Default version when none specified
    'default_version' => 'latest',

    // Fallback behavior
    'fallback' => [
        'enabled' => true,
        'strategy' => 'previous',
    ],

    // Sunset behavior: 'reject', 'warn', 'allow'
    'sunset' => [
        'action' => 'reject',
        'status_code' => 410,
    ],

    // Response headers
    'headers' => [
        'enabled' => true,
        'include' => [
            'version' => true,
            'deprecation' => true,
            'sunset' => true,
        ],
    ],
];
```

Testing
-------

[](#testing)

```
composer test
```

Code Quality
------------

[](#code-quality)

```
# Run all quality checks
composer full

# Individual checks
composer test:lint   # Laravel Pint
composer test:types  # PHPStan
composer test:unit   # Pest
```

Changelog
---------

[](#changelog)

Please see [RELEASES](RELEASES.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

Please review [our security policy](SECURITY.md) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Jean-Marc Strauven](https://github.com/Grazulex)
- [All Contributors](../../contributors)

Thanks
------

[](#thanks)

- [@maks-oleksyuk](https://github.com/maks-oleksyuk) - Bug reports and testing
- [@sameededitz](https://github.com/sameededitz) - Feature request for subdomain and multi-domain routing

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance85

Actively maintained with recent releases

Popularity39

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.9% 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

Every ~3 days

Total

12

Last Release

107d ago

Major Versions

v0.0.3 → v1.0.02025-12-25

v1.2.0 → v2.0.02026-01-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/888105bd54b6b7f7905523a16a1d08eebc2e5d39b19a4c174b5961bb4d52929b?d=identicon)[Grazulex](/maintainers/Grazulex)

---

Top Contributors

[![Grazulex](https://avatars.githubusercontent.com/u/4521546?v=4)](https://github.com/Grazulex "Grazulex (46 commits)")[![akrista](https://avatars.githubusercontent.com/u/23145794?v=4)](https://github.com/akrista "akrista (1 commits)")

---

Tags

apilaravelpackageapilaravelversioningdeprecationsunsetapi-versionrfc-8594rfc-7231

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/grazulex-laravel-apiroute/health.svg)

```
[![Health](https://phpackages.com/badges/grazulex-laravel-apiroute/health.svg)](https://phpackages.com/packages/grazulex-laravel-apiroute)
```

###  Alternatives

[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M107](/packages/laravel-cashier)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[andreaselia/laravel-api-to-postman

Generate a Postman collection automatically from your Laravel API

1.0k586.2k3](/packages/andreaselia-laravel-api-to-postman)[laravel/cashier-paddle

Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services.

264778.4k3](/packages/laravel-cashier-paddle)[shahghasiadil/laravel-api-versioning

Elegant attribute-based API versioning solution for Laravel applications with built-in deprecation management and version inheritance

2913.6k](/packages/shahghasiadil-laravel-api-versioning)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)

PHPackages © 2026

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