Skip to content
Jean-Marc Strauven edited this page Dec 23, 2025 · 2 revisions

Laravel ApiRoute

Complete API versioning lifecycle management for Laravel

Latest Version on Packagist Tests Total Downloads


What is Laravel ApiRoute?

Laravel ApiRoute is a powerful package that provides complete API versioning lifecycle management for Laravel applications. It handles everything from version detection to deprecation headers, making it easy to manage multiple API versions in production.

Key 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, Beta, Deprecated, Sunset 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

Quick Navigation

Getting Started Core Features Advanced
Installation Version Declaration Usage Tracking
Getting Started Detection Strategies Events
Configuration HTTP Headers Exceptions
Version Lifecycle Advanced Usage
Middleware
Artisan Commands

Learning Paths

Beginner Path

  1. Installation - Install the package
  2. Getting Started - First API version in 5 minutes
  3. Examples - Common use cases

Intermediate Path

  1. Configuration - Customize behavior
  2. Detection Strategies - Choose your versioning strategy
  3. Version Lifecycle - Manage deprecation and sunset
  4. Artisan Commands - CLI tools

Advanced Path

  1. HTTP Headers - RFC compliance
  2. Usage Tracking - Analytics and monitoring
  3. Events - Hook into version events
  4. Advanced Usage - Custom implementations

Quick Example

use Grazulex\ApiRoute\Facades\ApiRoute;

// Version 1 - Deprecated, sunset planned
ApiRoute::version('v1', function () {
    Route::apiResource('users', UserController::class);
})
->deprecated('2025-06-01')
->sunset('2025-12-01');

// Version 2 - Current stable version
ApiRoute::version('v2', function () {
    Route::apiResource('users', UserController::class);
})->current();

// Version 3 - Beta/Preview
ApiRoute::version('v3', function () {
    Route::apiResource('users', UserController::class);
})->beta();

Requirements

  • PHP: 8.3+
  • Laravel: 12.x

External Resources


RFC Standards

This package implements the following RFC standards:

RFC Description Header
RFC 8594 The Sunset HTTP Header Field Sunset
RFC 7231 HTTP/1.1 Semantics Deprecation
RFC 8288 Web Linking Link

License

The MIT License (MIT). Please see License File for more information.

Author

Created by Jean-Marc Strauven (@Grazulex)

Clone this wiki locally