PHPackages                             ahmedessam/api-versionizer - 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. ahmedessam/api-versionizer

ActiveLibrary[API Development](/categories/api)

ahmedessam/api-versionizer
==========================

Laravel-ApiVersionizer is a versatile package for managing API versioning in Laravel applications. It supports flexible routing, automatic versioning, and deprecation notices, ensuring smooth transitions between API versions while maintaining backward compatibility.

v1.5.0(1y ago)198MITPHPPHP ^8.2

Since Aug 31Pushed 1y ago1 watchersCompare

[ Source](https://github.com/aahmedessam30/api-versionizer)[ Packagist](https://packagist.org/packages/ahmedessam/api-versionizer)[ RSS](/packages/ahmedessam-api-versionizer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (2)Versions (8)Used By (0)

API Versionizer
===============

[](#api-versionizer)

**API Versionizer** is a versatile package for managing API versioning in Laravel applications. It supports flexible routing, automatic versioning, and deprecation notices, ensuring smooth transitions between API versions while maintaining backward compatibility.

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

[](#installation)

You can install the package via Composer:

```
composer require ahmedessam/api-versionizer
```

Usage
-----

[](#usage)

### Step 1: Publish Configuration File

[](#step-1-publish-configuration-file)

Before using the API Versionizer package, you must publish the configuration file using Laravel's built-in command:

```
php artisan vendor:publish --tag=apiversionizer-config
```

This will create a configuration file named `api-versionizer.php` in your `config` directory. The configuration file contains the following options:

- **current\_version**: The current version of the API.
- **fallback\_version**: The fallback version to use if the requested version is not found.
- **strategy**: The versioning strategy to use (e.g., `uri`, `header`, `query`).
- **versioning\_key**: The key used for versioning (e.g., `v`, `version`).
- **prefix**: The prefix to use for versioned routes.
- **default\_version**: The default version to use if no version is specified.
- **default\_directory**: The default directory to use for versioned files.
- **versioned\_folders**: An array of directories containing versioned files.
- **middlewares**: An array of middleware classes to apply to versioned routes.
- **default\_files**: An array of default files to use for versioned routes.
- **use\_default\_namespace**: A flag to indicate whether to use the default namespace for versioned files.
- **versions**: An array of supported API versions.

### Step 2: Configure API Versions

[](#step-2-configure-api-versions)

Once the configuration file is published, you can configure the API versions by editing the `api-versionizer.php` file. You can specify the current version, fallback version, versioning strategy, versioning key, prefix, default version, default directory, versioned folders, middlewares, default files, and supported versions.

Here is an example configuration for API versioning:

```
'versions' => [
    'v1' => [
        'name'        => 'v1',
        'description' => 'First version of the API',
        'status'      => 'active',
        'files' => [
            [
                'name'        => 'users',
                'as'          => 'users',
                'prefix'      => 'users',
                'namespace'   => 'Users',
                'middlewares' => ['auth:api'],
            ],
        ],
    ],
    'v2' => [
        'name'        => 'v2',
        'description' => 'Second version of the API',
        'status'      => 'active',
        'files' => [
            [
                'name'        => 'users',
                'as'          => 'users',
                'prefix'      => 'users',
                'namespace'   => 'Users',
                'middlewares' => ['auth:api'],
            ],
            [
                'name'        => 'posts',
                'as'          => 'posts',
                'prefix'      => 'posts',
                'namespace'   => 'Posts',
                'group'       => 'admin',
                'middlewares' => ['auth:api'],
            ],
        ],
    ],
],
```

In this example, we define a version `v1` with a description and status. We also specify versioned files with their names, aliases, prefixes, namespaces, and middlewares.

**Note:** You can add as many versions and files as needed to support your API versioning requirements, status in the vesions array can be `active` or `inactive` or `deprecated` to indicate the status of the version.

### Step 3: Run Versionizer Command

[](#step-3-run-versionizer-command)

After configuring the API versions, you can run the Versionizer command to generate versioned routes and files automatically:

```
php artisan api:versionize --versions=v1,v2
```

This command will create versioned routes and files based on the configuration specified in the `api-versionizer.php` file. It will generate routes for each versioned file with the appropriate version prefix and middleware.

### Step 4: Access Versioned Routes

[](#step-4-access-versioned-routes)

Once the versioned routes are generated, you can access them using the version prefix in the URL. For example, to access the `users` route in version `v1`, you can use the following URL:

```
http://example.com/api/v1/users/users

```

This URL has the version prefix `v1` and the route prefix `users` specified in the configuration file.

### Note:

[](#note)

- The group key in the versioned files array is used to group the routes in folders, for example, if you have a group key with the value `admin`, the routes will be generated in a folder named `admin` in the routes directory.

Handle Deprecation Notices
--------------------------

[](#handle-deprecation-notices)

If you need to deprecate a version of the API, you can update the version status to `deprecated` in the configuration file and set `deprecated_at` to the date when the version will be deprecated. The Versionizer package will automatically handle deprecation notices and will return error when accessing a deprecated version.

Copy Version to New Version
---------------------------

[](#copy-version-to-new-version)

If you need to copy a version to a new version, you can run the following command:

```
php artisan api:versionize --copy=v1 --to=v2
```

This command will copy the version `v1` to version `v2` and will generate the versioned routes and files for the new version based on the existing version, and namespace will be updated to the new version.

Delete Version
--------------

[](#delete-version)

If you need to delete a version, you can run the following command:

```
php artisan api:versionize --delete=v1
```

This command will delete the version `v1` and will remove the versioned routes and files for the specified version.

Route Macros
------------

[](#route-macros)

If you want to use crud routes for a model, you can use the following route macros:

```
Route::crud('users', 'UserController');
```

This will generate the following routes for the `UserController`:

```
Route::apiResource('users', 'UserController');
Route::get('users/trash', 'UserController@trash')->name('users.trash');
Route::patch('users/{user}/restore', 'UserController@restore')->name('users.restore');
Route::delete('users/{user}/force-delete', 'UserController@forceDelete')->name('users.force-delete');
```

Features
========

[](#features)

- **Flexible Routing**: Define versioned routes with custom prefixes, namespaces, and middlewares.
- **Automatic Versioning**: Generate versioned routes and files automatically based on the configuration.
- **Deprecation Notices**: Handle deprecation notices for API versions and return errors when accessing deprecated versions.
- **Version Copying**: Copy existing versions to new versions and generate versioned routes and files for the new version.
- **Version Deletion**: Delete existing versions and remove versioned routes and files for the specified version.

Requirements
============

[](#requirements)

- PHP 8.2 or higher
- Laravel 10.0 or higher
- Composer

License
=======

[](#license)

The API Versionizer package is open-source software licensed under the [MIT license](https://opensource.org/licenses/MIT).

Author
------

[](#author)

- **Ahmed Essam**
    - [GitHub Profile](https://github.com/aahmedessam30)
    - [Packagist](https://packagist.org/packages/ahmedessam/api-versionizer)
    - [LinkedIn](https://www.linkedin.com/in/aahmedessam30)
    - [Email](mailto:aahmedessam30@gmail.com)

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

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

Issues
------

[](#issues)

If you find any issues with the package or have any questions, please feel free to open an issue on the GitHub repository.

Enjoy using the API Versionizer package in your Laravel applications! 🚀

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance41

Moderate activity, may be stable

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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 ~21 days

Recently: every ~30 days

Total

7

Last Release

493d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/14383efd445985cf037e39f51ce0228eab1800ddf41cd845457daae1bcd8c192?d=identicon)[aahmedessam30](/maintainers/aahmedessam30)

---

Top Contributors

[![aahmedessam30](https://avatars.githubusercontent.com/u/63825434?v=4)](https://github.com/aahmedessam30 "aahmedessam30 (24 commits)")

### Embed Badge

![Health badge](/badges/ahmedessam-api-versionizer/health.svg)

```
[![Health](https://phpackages.com/badges/ahmedessam-api-versionizer/health.svg)](https://phpackages.com/packages/ahmedessam-api-versionizer)
```

###  Alternatives

[andreaselia/laravel-api-to-postman

Generate a Postman collection automatically from your Laravel API

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

The official Laravel plugin for Saloon

765.7M125](/packages/saloonphp-laravel-plugin)[mll-lab/laravel-graphiql

Easily integrate GraphiQL into your Laravel project

683.2M9](/packages/mll-lab-laravel-graphiql)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[neuron-core/neuron-laravel

Official Neuron AI Laravel SDK.

10710.0k](/packages/neuron-core-neuron-laravel)[grantholle/powerschool-api

A Laravel package to make interacting with PowerSchool less painful.

1715.6k1](/packages/grantholle-powerschool-api)

PHPackages © 2026

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