Add explicit @version special route token support for API major versioning within a single module
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 45/100
Research direction
Start by tracing @version handling across src/Router/PatternCompiler.php, src/Router/RouteBuilder.php, src/Router/RouteDispatcher.php, src/Router/MatchedRoute.php, and src/Http/Traits/Request/Route.php; inspect the DemoApi templates and dependencies #546 and #548 first. Done means supported configured major versions match, version-aware controllers resolve within one module, version values remain route context, and tests cover matching and resolution.
Written by the indexing model from the issue text.
Description
Summary
Add API major versioning support based on the explicit special route token:
@version
so a single API module can expose multiple major API versions concurrently, such as:
/api/v1/posts/api/v2/posts
without treating each version as a separate module.
Why
Quantum needs a clean framework-level API versioning model.
The intended ownership model is:
- one logical
Apimodule - multiple supported API major versions inside that module
With the special route token foundation in place, versioning can be expressed explicitly in route patterns instead of relying on:
- duplicated route trees
- positional URL conventions
- separate modules per version
- hidden dispatch tricks
Goal
Allow routes to explicitly declare API major version position using:
@version
and let the framework treat the matched version as framework-owned route context for version-aware controller resolution.
Proposed Direction
API routes that are versioned should explicitly include:
@version
Examples:
$route->get('@version/posts', 'PostController', 'posts');
$route->get('@version/post/[uuid=:any]', 'PostController', 'post');
$route->post('@version/signin', 'AuthController', 'signin');
This should allow URLs such as:
/api/v1/posts/api/v2/posts/api/v1/signin
depending on module prefix configuration and supported versions.
Config Direction
Supported API versions should be declared in module config.
A likely shape is:
'Api' => [
'prefix' => 'api',
'enabled' => true,
'versions' => ['v1', 'v2'],
]
The route token:
@version
should then match only those configured supported versions.
Controller Resolution Direction
Matched version values should be used by the framework to resolve version-specific controllers inside the same module.
Examples:
-
v1+PostController
resolves to:{ModuleBaseNamespace}\Api\Controllers\V1\PostController
-
v2+PostController
resolves to:{ModuleBaseNamespace}\Api\Controllers\V2\PostController
This allows one route shape to map to different major-version controller implementations inside a single module.
Important behavior
The resolved version should be:
- matched through the
@versiontoken - validated against configured supported versions
- made available to framework internals as version route context
- used for version-aware controller resolution
- kept distinct from ordinary controller action parameters by default
Scope
This ticket should focus on major API versioning only.
It should not introduce:
- minor or patch versioning in the URL
- header-based minor/patch runtime negotiation
- separate modules per API version
Minor and patch changes should remain outside the first implementation scope.
Acceptance Criteria
- routes can explicitly declare API version position using
@version - matched
@versionvalues are validated against configured supported versions - a single API module can expose multiple supported major versions concurrently
- matched version values are used for version-aware controller resolution within the same module
- routed version values do not become ordinary positional controller action parameters by default
- tests cover
@versionroute matching and version-aware controller resolution behavior - templates and examples can be updated to use
@versionwhere appropriate
Notes
Relevant code:
src/Router/PatternCompiler.phpsrc/Router/RouteBuilder.phpsrc/Router/RouteDispatcher.phpsrc/Router/MatchedRoute.phpsrc/Http/Traits/Request/Route.phpsrc/Module/Templates/DemoApi
This ticket depends on:
- Dominant language
- PHP
- Stars
- 36
- Forks
- 22
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from quantum-php/framework
-
routing testing
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
quantum-php/framework#547 ·
-
view
Difficulty 1/5 Under an hour Newbie friendliness 75/100
quantum-php/framework#542 ·
-
enhancement http
Difficulty 5/5 Over a week Newbie friendliness 35/100
quantum-php/framework#565 · 1 comment ·
-
components view
Difficulty 5/5 Over a week Newbie friendliness 42/100
quantum-php/framework#551 ·
-
lang routing
Difficulty 5/5 Over a week Newbie friendliness 45/100
quantum-php/framework#549 ·
All issues in quantum-php/framework
Similar issues
-
a11y admissions.uiowa.edu needs grooming SiteImprove best practice
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Save States Menu Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
pluginsGLPI/datainjection#673 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
octobercms/october#6130 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
getgrav/grav-plugin-form#656 ·