
Frontline API for Laravel
Puts a Laravel API behind the Frontline API gateway: publishes its routes, tiers and keys as signed sheets, admits only the requests the gateway signed, and counts what the gateways report.
The Frontline API gateway stands in front of the API host of your Laravel application. Every request passes it first: it checks the caller's key, the key's abilities and limits, and what the route allows, and only then forwards the request to Laravel, signed. The gateway keeps no rules of its own. This package writes them from your application into signed sheets, which the gateways read from a shared Redis store, and it reads back what the gateways count.
The package
- declares every route of the API host for the gateway, with its ability, its limit class and how the gateway treats it (Declaring routes);
- publishes the product sheet with the routes and tiers, and a key sheet per scope with your keys, signed with a key only your application holds (Publishing the sheets, The signing key);
- lets a request reach the API host only when the gateway signed it (The entrance for the gateway);
- blocks a route at once, lets the gateway keep a response, and limits a second time behind the gateway (Blocking a route, Letting the gateway keep a response, Laravel's own limits);
- counts what the gateways report, and shows whether they work from current sheets (Counts, Status and health).
Requirements
- A Frontline API gateway in front of the API host. The gateway is a separate service and not yet publicly available.
- PHP 8.4+ (tested on 8.4.27, 8.5.x and 8.6.x) with the
sodiumextension, which signs the sheets with Ed25519 - Laravel 13+, as the full
laravel/frameworkrather than separateilluminate/*components - Redis 6.2 or later, or Valkey, on a server your gateways reach, for the sheets and the counts
- A filesystem disk on the object storage your gateways read while the store is down
- A queue worker, the scheduler, and a default cache store that can hold a lock, such as
redisordatabase
Installation
composer require pushery/frontline-api-for-laravel
The service provider is registered automatically through package discovery. Then, in this order:
- Name the product, its environment, the API host, the store and the disk (Configuration).
- Make the signing key, and give its public half to every gateway (The signing key).
- Tell the package where your keys and tiers come from (Keys and tiers).
- Declare the routes of the API host, and put the gateway's check on them (Declaring routes, The entrance for the gateway).
- Run the scheduler and a queue worker, publish in each deployment with
php artisan frontline:publish, and check the result withphp artisan frontline:status(Publishing the sheets, Status and health).
A new release of the gateway or of this package can move the protocol between them to a new version; Upgrading the protocol gives the order.