Resolving the revision
The revision middleware decides the revision of each request. It runs a chain of resolvers: the first one that
returns a revision wins.
Route::middleware('revision')->group(function () {
Route::get('/orders/{order}', [OrderController::class, 'show']);
});
Configure the chain
'resolvers' => [
HeaderResolver::class => ['name' => 'Api-Revision'],
// PathResolver::class => ['parameter' => 'revision'],
// QueryResolver::class => ['name' => 'revision'],
],
'default' => 'latest',
| Resolver | Reads | Option (default) |
|---|---|---|
Laravel\Http\Resolvers\HeaderResolver | a request header | name (Api-Revision) |
Laravel\Http\Resolvers\PathResolver | a route parameter | parameter (revision) |
Laravel\Http\Resolvers\QueryResolver | a query parameter | name (revision) |
The options are named constructor arguments; the container injects the rest. When no resolver answers, default
applies: latest (the head), oldest, a backed value of the enum, or a resolver class.
What the client gets
Every response carries the revision it was rendered in, under response_header (Api-Revision), and a Vary header
on the headers the chain reads. Once the revision's #[Meta] declares them, it also carries:
Deprecation: @<unix time>(RFC 9745) fromdeprecatedAt;Sunset: <HTTP date>fromsunsetAt.
An unknown value stops the chain and is answered with 400, listing the accepted values:
{
"message": "Unknown API revision 'autumn-24', expected one of: …",
"revision": "autumn-24",
"accepted": ["genesis", "winter-25", "spring-26"]
}
Path mode
With a PathResolver in the chain, Route::revisioned() prefixes its routes with the revision, constrains it to the
enum values and adds the middleware:
Route::revisioned(function (Router $router) {
// /winter-25/orders/1
$router->get('/orders/{order}', [OrderController::class, 'show']);
});
The revision parameter never reaches your controllers, and route() generates URLs in the revision of the request.
Pin the revision of an account
A custom resolver implements RevisionResolver. Returning null lets the next resolver of the chain answer.
use Ark4ne\ApiRevisions\Laravel\Http\RevisionResolver;
use Ark4ne\ApiRevisions\Revisions\Revision;
final readonly class AccountPinnedResolver implements RevisionResolver
{
public function resolve(Request $request): ?Revision
{
$account = $request->user();
return $account instanceof Account ? $account->api_revision : null;
}
}
'resolvers' => [
AccountPinnedResolver::class => [],
HeaderResolver::class => ['name' => 'Api-Revision'],
],
Here api_revision is cast to ApiRevision on the model. An account pinned to genesis gets genesis without
sending a header; an account with no pinned revision falls through to the header.
A resolver reading request headers also implements Laravel\Http\VariesOn (headers(): array), so that they are
listed in the Vary header.