Download the PHP package cleaniquecoders/laravel-api-version without Composer
On this page you can find all versions of the php package cleaniquecoders/laravel-api-version. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cleaniquecoders/laravel-api-version
More information about cleaniquecoders/laravel-api-version
Files in cleaniquecoders/laravel-api-version
Package laravel-api-version
Short Description Effortlessly manage your Laravel API versions with flexible, header-based versioning control.
License MIT
Homepage https://github.com/cleaniquecoders/laravel-api-version
Informations about the package laravel-api-version
Laravel API Version
Effortlessly manage your Laravel API versions with flexible, header-based versioning control.
Installation
You can install the package via composer:
You can publish the config file with:
Usage
Configuration
This will create a config/api-version.php
file where you can customize options like the default version, headers, version format, and the root namespace for versioned controllers.
Example configuration:
Middleware Setup
The api.version
middleware is registered automatically. This middleware allows for automatic version detection based on headers or explicit version specification in the route.
Defining Versioned Routes
Option 1: Header-Based Version Detection
To enable automatic version detection from headers, use the api.version
middleware in your routes/api.php
:
This setup detects versions from the Accept
or X-API-Version
headers, dynamically routing requests to the correct versioned namespace.
Option 2: Explicitly Setting the Version
You can explicitly define a version for a route or route group by passing the version to the middleware. This approach bypasses header detection.
In this example:
api.version:v1
directs routes in the group to thev1
namespace.api.version:v2
directs routes to thev2
namespace, ignoring headers.
Example Requests
Using Accept
Header
Using Custom Header (X-API-Version
)
Explicitly Versioned Route
If the route is explicitly defined as api.version:v2
, no header is needed to access version 2.
Testing
Run the package tests:
Changelog
Please see CHANGELOG for details on recent updates.
Contributing
Please see CONTRIBUTING for contribution guidelines.
Security Vulnerabilities
Please review our security policy for reporting security issues.
Credits
- Nasrul Hazim Bin Mohamad
- All Contributors
License
The MIT License (MIT). See the License File for details.
All versions of laravel-api-version with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^10.0||^11.0