| Install | |
|---|---|
composer require akira/laravel-spectra |
|
| Latest Version: | v0.2.0 |
| PHP: | ^8.4 |
Illuminate your API — Interactive API inspector for Laravel 12 with Inertia + React.
Spectra is a powerful, developer-focused API inspector built exclusively for Laravel 12 applications. It provides an embedded, interactive console accessible at /spectra that helps you explore, test, and debug your API endpoints during development.
Install the package via Composer:
composer require --dev akira/laravel-spectra
Install and publish configuration:
php artisan spectra:install
This will publish the configuration file to config/spectra.php.
The configuration file provides comprehensive control over Spectra's behavior:
return [
// Enable/disable Spectra (defaults to local environment only)
'enabled' => env('SPECTRA_ENABLED', app()->environment('local')),
// Restrict to local environment only
'only_local' => env('SPECTRA_ONLY_LOCAL', true),
// Authentication guard to use
'guard' => env('SPECTRA_GUARD', 'web'),
// Gate for impersonation feature
'impersonation_gate' => 'use-spectra',
// Rate limiting for execute endpoint
'rate_limit' => [
'max' => 60,
'per_minutes' => 1,
],
// Headers to strip from requests
'strip_headers' => [
'authorization',
'cookie',
'x-api-key',
],
// Fields to mask in responses
'mask_fields' => [
'password',
'token',
'authorization',
'api_key',
'secret',
],
];
Once installed, visit /spectra in your browser when running in a local environment. You must be authenticated and have the use-spectra permission.
By default, Spectra defines a use-spectra gate that checks if the user has a developer role. You can customize this in your AuthServiceProvider:
use Illuminate\Support\Facades\Gate;
Gate::define('use-spectra', function ($user) {
return $user->email === 'admin@example.com';
});
Spectra supports four authentication modes for executing requests:
use-spectra gate approval)Spectra automatically generates JSON Schema (2020-12) from your FormRequest validation rules. Supported validation rules include:
string, integer, numeric, boolean, arrayemail, url, date, uuidmin, max, between, in (enum), regexfile, image, mimesnullable, required, sometimesSave frequently used requests as collections:
Export/import collections as JSON for sharing with your team.
Spectra is designed with security as a top priority:
Spectra will automatically return a 404 error when:
enabled config is falseonly_local is true and the environment is not localNever enable Spectra in production environments.
All Spectra services are bound to the container and can be extended or replaced:
app()->bind(RouteScanner::class, function ($app) {
return new CustomRouteScanner($app['router']);
});
Override the schema builder to add custom rule conversions:
app()->extend(SchemaBuilder::class, function ($builder, $app) {
// Add custom logic
return $builder;
});
Run the test suite:
composer test
Run static analysis:
composer analyse
Format code:
composer format
Spectra includes GitHub Actions workflows for:
Please see CHANGELOG for more information on what has changed recently.
Contributions are welcome! Please follow the conventional commits specification for all commits.
If you discover a security vulnerability, please email security@akira-io.com. All security vulnerabilities will be promptly addressed.
The MIT License (MIT). Please see License File for more information.