PHPackages                             mnarbash/api-versioning-by-header-request - 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. mnarbash/api-versioning-by-header-request

ActiveLibrary[API Development](/categories/api)

mnarbash/api-versioning-by-header-request
=========================================

A package for managing API versioning in Laravel using request headers

1.0.2(3y ago)268MITPHP

Since Jan 6Pushed 3y ago1 watchersCompare

[ Source](https://github.com/mnarbash/api-versioning-by-header-request)[ Packagist](https://packagist.org/packages/mnarbash/api-versioning-by-header-request)[ RSS](/packages/mnarbash-api-versioning-by-header-request/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)DependenciesVersions (4)Used By (0)

Laravel API Versioning By Header Request
========================================

[](#laravel-api-versioning-by-header-request)

[![Latest Version on Packagist](https://camo.githubusercontent.com/cfe9019349e613c0b8b6bc9c0ae36e86f0799b21df0017027dfa9d65df3f9c1b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6e6172626173682f6170692d76657273696f6e696e672d62792d6865616465722d726571756573742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mnarbash/api-versioning-by-header-request)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/0d286e60a80e5de45341d92db788d4bcef547bbe1224bc224fb4426ad43d1af4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6e6172626173682f6170692d76657273696f6e696e672d62792d6865616465722d726571756573742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mnarbash/api-versioning-by-header-request)

This package provides middleware for managing API versioning in Laravel using request headers.

Features
--------

[](#features)

- **You Not Need To Change Your Routes Endpoints**. You can use the same endpoints for all versions of your API.
- **API versioning by header request**: This package allows you to version your API by adding the `API-VERSION` header to the request. You can specify the supported API versions and the default API version in the configuration file.
- **App version checking**: This package includes a middleware that checks the `APP-VERSION` header in the request against the supported app versions and the minimum supported app version specified in the configuration file. If the app version is not supported, the middleware returns an error response to update app.
- **Customizable folder structure**: You can specify a custom folder structure for the API versions in the configuration file. This allows you to organize your controllers and routes in a way that makes sense for your application.
- **Api Versioning base on your controller classes**: The package allows you to version your API by multi controller classes in your route define.

Youtube Video
-------------

[](#youtube-video)

Check out this video to see how to use this package in your project.

[![Laravel API Versioning By Header Request](https://camo.githubusercontent.com/f50ee24e284c37cc904615592c44b28c37be18fe0beb882b847ec0aa3893b964/68747470733a2f2f696d672e796f75747562652e636f6d2f76692f32486546434a6965564c6f2f302e6a7067)](https://www.youtube.com/watch?v=2HeFCJieVLo)

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

[](#installation)

To install the package, run the following command:

```
composer require mnarbash/api-versioning-by-header-request
```

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

[](#configuration)

Add ServiceProvider to `config/app.php` in `providers` section:

```
Mnarbash\ApiVersioningByHeaderRequest\ApiVerServiceProvider::class,
```

To configure the package, publish the configuration file using the following command:

```
php artisan vendor:publish --provider="Mnarbash\ApiVersioningByHeaderRequest\ApiVerServiceProvider" --tag=config
```

This will create a `config/api-versioning.php` file in your project. You can modify the following options in this file:

- `check_app_version_support`: This option tells the package whether to check the app version support. If set to `true`, the package will check the app version and return an error response if the app version is not supported.
- `api_versioning_enabled`: This option tells the package whether to enable API versioning. If set to `true`, the package will check the `API-VERSION` header in the request and use it to determine the version of the API to be used.
- `default_api_version`: This option specifies the default API version to be used when the `API-VERSION` header is not present in the request.
- `not_do_anything_when_version_is_not_set`: This option tells the package whether to do anything when the version is not set. If set to `true`, the package will not change the controller name when the version is not set.
- `default_app_version`: This option specifies the default app version to be used when the `APP-VERSION`header is not present in the request.
- `min_supported_app_version`: This option specifies the minimum supported app version. If the app version in the request is less than this version, return an error response.
- `update_urls`: This option specifies the URLs to show update app.
- `not_support_response_status_code`: this option specifies the status code of the response when the app version is not supported.

To use the check api and redirect to new controller, apply it to a route as follows:

-**Note**: Add the newer controller in the first of array. We use this order to check the version and redirect to the older controller if version is not exist. **Example**: If you have 2 controller with version 1 and 2 and you want to redirect to version 1 if version 2 is not exist,

```
    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
    ]))
```

Full Example For Route File
---------------------------

[](#full-example-for-route-file)

```
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,
        ]
    ));
});
```

Also you can get api version from anywhere in your code like this:

```
    $apiVersion = ApiVersioning::getApiVersion();
```

The package includes the `CheckAppVersion` middleware:

- `CheckAppVersion`: This middleware checks the app version in the `APP-VERSION` request header. If the version is not supported, it returns an error.
- to use the check app middleware, apply it to a api $middlewareGroups in app/Http/Kernel file as follows:

```
    use Mnarbash\ApiVersioningByHeaderRequest\Middleware\CheckAppVersion;

    protected $middlewareGroups = [
        'api' => [
        // ...
                  CheckAppVersion::class,
        ],
    ];
```

License
-------

[](#license)

This package is licensed under the MIT license. See the `LICENSE` file for more information.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

Every ~1 days

Total

3

Last Release

1226d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0d22fb28ed9ca091012a3308834184e09801cac76de6d5b5b2445c492024883e?d=identicon)[mnarbash](/maintainers/mnarbash)

---

Top Contributors

[![mnarbash](https://avatars.githubusercontent.com/u/22705325?v=4)](https://github.com/mnarbash "mnarbash (13 commits)")

---

Tags

api-versioningapp-versioninglaravelapilaravellaravel-packageversioning

### Embed Badge

![Health badge](/badges/mnarbash-api-versioning-by-header-request/health.svg)

```
[![Health](https://phpackages.com/badges/mnarbash-api-versioning-by-header-request/health.svg)](https://phpackages.com/packages/mnarbash-api-versioning-by-header-request)
```

###  Alternatives

[kyon147/laravel-shopify

Shopify package for Laravel to aide in app development

473252.9k](/packages/kyon147-laravel-shopify)[joisarjignesh/bigbluebutton

BigBlueButton Server API Library for Laravel

162145.5k1](/packages/joisarjignesh-bigbluebutton)[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)[wayofdev/laravel-symfony-serializer

📦 Laravel wrapper around Symfony Serializer.

2113.6k](/packages/wayofdev-laravel-symfony-serializer)[mahdimajidzadeh/laravel-unsplash

Laravel package for Unsplash Api

1111.4k](/packages/mahdimajidzadeh-laravel-unsplash)

PHPackages © 2026

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